Skip to content

Commit 57bb1d4

Browse files
Fix a flake in ShellTest.SecondaryVsyncCallbackShouldBeCalledAfterVsyncCallback (flutter#190490)
That test calls the engine's ScheduleSecondaryVsyncCallback and ScheduleFrame APIs. If a vsync occurs between the two calls, then the secondary callback will be executed at that vsync, but the frame will be scheduled at the next vsync. That will cause a false negative in the test. This PR changes the test to execute the API calls shortly after a vsync happens. That should ensure that both calls happen during the same vsync interval. This also fixes an issue where VsyncWaiter::FireCallback was not properly resetting the VsyncWaiter's callback. The failure to reset the callback meant that a second call to AsyncWaitForVsync with a different callback would not actually take effect. Fixes flutter#190430
1 parent 67cfcfb commit 57bb1d4

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎engine/src/flutter/shell/common/shell_unittests.cc‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,23 +2296,34 @@ TEST_F(ShellTest, SecondaryVsyncCallbackShouldBeCalledAfterVsyncCallback) {
22962296
// Wait for the application to attach the listener.
22972297
latch.Wait();
22982298

2299+
auto vsync_task = [&]() {
2300+
shell->GetEngine()->ScheduleSecondaryVsyncCallback(0, [&]() {
2301+
if (!test_started) {
2302+
return;
2303+
}
2304+
EXPECT_TRUE(is_on_begin_frame_called);
2305+
EXPECT_FALSE(is_secondary_callback_called);
2306+
is_secondary_callback_called = true;
2307+
count_down_latch.CountDown();
2308+
});
2309+
shell->GetEngine()->ScheduleFrame();
2310+
test_started = true;
2311+
};
2312+
2313+
// Run the test task after a vsync occurs so that the
2314+
// ScheduleSecondaryVsyncCallback and ScheduleFrame calls will happen within
2315+
// the same vsync interval.
22992316
fml::TaskRunner::RunNowOrPostTask(
23002317
shell->GetTaskRunners().GetUITaskRunner(), [&]() {
2301-
shell->GetEngine()->ScheduleSecondaryVsyncCallback(0, [&]() {
2302-
if (!test_started) {
2303-
return;
2304-
}
2305-
EXPECT_TRUE(is_on_begin_frame_called);
2306-
EXPECT_FALSE(is_secondary_callback_called);
2307-
is_secondary_callback_called = true;
2308-
count_down_latch.CountDown();
2309-
});
2310-
shell->GetEngine()->ScheduleFrame();
2311-
test_started = true;
2318+
auto vsync_waiter = shell->GetEngine()->GetVsyncWaiter().lock();
2319+
vsync_waiter->AsyncWaitForVsync(
2320+
[&](auto frame_timings_recorder) { vsync_task(); });
23122321
});
2322+
23132323
count_down_latch.Wait();
23142324
EXPECT_TRUE(is_on_begin_frame_called);
23152325
EXPECT_TRUE(is_secondary_callback_called);
2326+
23162327
DestroyShell(std::move(shell), task_runners);
23172328
}
23182329

‎engine/src/flutter/shell/common/vsync_waiter.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
9494

9595
{
9696
std::scoped_lock lock(callback_mutex_);
97-
callback = std::move(callback_);
97+
callback_.swap(callback);
9898
for (auto& pair : secondary_callbacks_) {
9999
secondary_callbacks.push_back(std::move(pair.second));
100100
}

0 commit comments

Comments
 (0)