@@ -43,11 +43,12 @@ TEST_F(ShellTest, ImageReleasedAfterFrame) {
4343 auto nativeDone = [&](Dart_NativeArguments args) { message_latch.Signal (); };
4444
4545 Settings settings = CreateSettingsForFixture ();
46+ auto task_runner = CreateNewThread ();
4647 TaskRunners task_runners (" test" , // label
4748 GetCurrentTaskRunner (), // platform
48- CreateNewThread (), // raster
49- CreateNewThread (), // ui
50- CreateNewThread () // io
49+ task_runner, // raster
50+ task_runner, // ui
51+ task_runner // io
5152 );
5253
5354 AddNativeCallback (" CaptureImageAndPicture" ,
@@ -74,22 +75,19 @@ TEST_F(ShellTest, ImageReleasedAfterFrame) {
7475 ASSERT_TRUE (current_picture);
7576 ASSERT_TRUE (current_image);
7677
77- ASSERT_FALSE (current_picture->unique ());
78- ASSERT_FALSE (current_image->unique ());
79-
80- // Drain the raster task runner to get to the end of the frame.
81- fml::AutoResetWaitableEvent latch;
82- task_runners.GetRasterTaskRunner ()->PostTask ([&latch]() { latch.Signal (); });
83- latch.Wait ();
84-
85- // Tell the engine we're idle.
86- task_runners.GetUITaskRunner ()->PostTask (
87- [&latch, engine = shell->GetEngine ()]() {
88- ASSERT_TRUE (engine);
89- engine->NotifyIdle (Dart_TimelineGetMicros () + 10000 );
90- latch.Signal ();
91- });
92- latch.Wait ();
78+ // AOT modes are fast enough that we get here before the task runner has
79+ // had a chance to drain. Make sure that if the picture or image are not
80+ // already unique, at least one idle notification has a chance to process
81+ // after rasterization has occurred.
82+ if (!current_picture->unique () || !current_image->unique ()) {
83+ fml::AutoResetWaitableEvent latch;
84+ task_runner->PostTask ([&latch, engine = shell->GetEngine ()]() {
85+ ASSERT_TRUE (engine);
86+ engine->NotifyIdle (Dart_TimelineGetMicros () + 10000 );
87+ latch.Signal ();
88+ });
89+ latch.Wait ();
90+ }
9391
9492 EXPECT_TRUE (current_picture->unique ());
9593 current_picture.reset ();
0 commit comments