Commit 14ebf789 authored by Olle Liljenzin's avatar Olle Liljenzin Committed by Commit Bot

Fix flaky PerfettoTaskRunnerTest.SequentialTasks

Reset weak pointers before signaling work is done. Otherwise it will be
a race, where the main thread could destruct the factory before the weak
pointers get destructed after being dereferenced on the other thread.

Bug: 1071409
Change-Id: I8f06592b09bddb325270ef5e09d6c5a1eb2dac19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2159708
Commit-Queue: oysteine <oysteine@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762049}
parent 2de60daf
......@@ -125,9 +125,16 @@ TEST_F(PerfettoTaskRunnerTest, SequentialTasks) {
SetTaskExpectations(wait_for_tasks.QuitClosure(), 3);
auto weak_ptr = destination()->GetWeakPtr();
task_runner()->PostTask([weak_ptr]() { weak_ptr->TestTask(1); });
task_runner()->PostTask([weak_ptr]() { weak_ptr->TestTask(2); });
task_runner()->PostTask([weak_ptr]() { weak_ptr->TestTask(3); });
for (int i = 1; i <= 3; ++i) {
task_runner()->PostTask([=]() mutable {
auto* dest = weak_ptr.get();
// The weak pointer must be reset before TestTask() is called, otherwise
// there will be a race where the factory could be destructed on main
// thread while still bound to the task runner sequence.
weak_ptr.reset();
dest->TestTask(i);
});
}
wait_for_tasks.Run();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment