From 7cecdf4cd5ce0fc37680d1b4b86cf7c13ce24092 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 18 Sep 2019 15:16:37 -0700 Subject: [PATCH 1/2] Update secondary-isolate-launch test to verify that secondary isolate gets shutdown before root isolate exits. --- runtime/dart_isolate.cc | 4 ++++ runtime/dart_isolate_unittests.cc | 11 ++++++++--- runtime/fixtures/runtime_test.dart | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 55ac852edacd3..b8119b139da34 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -774,6 +774,10 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair( void DartIsolate::DartIsolateShutdownCallback( std::shared_ptr* isolate_group_data, std::shared_ptr* isolate_data) { + TRACE_EVENT0("flutter", "DartIsolate::DartIsolateShutdownCallback"); + FML_DLOG(INFO) << "DartIsolateShutdownCallback" + << " isolate_group_data " << isolate_group_data + << " isolate_data " << isolate_data; isolate_group_data->get()->OnShutdownCallback(); } diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index 73da3c6a9678e..a59b62353843b 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -360,6 +360,7 @@ TEST_F(DartIsolateTest, CanSaveCompilationTrace) { TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) { fml::CountDownLatch latch(3); + fml::AutoResetWaitableEvent child_shutdown_latch; AddNativeCallback("NotifyNative", CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) { latch.CountDown(); @@ -371,14 +372,18 @@ TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) { ASSERT_EQ("Hello from code is secondary isolate.", message); latch.CountDown(); }))); - const auto settings = CreateSettingsForFixture(); + auto settings = CreateSettingsForFixture(); + settings.isolate_shutdown_callback = [&child_shutdown_latch]() { + child_shutdown_latch.Signal(); + }; auto vm_ref = DartVMRef::Create(settings); auto isolate = RunDartCodeInIsolate(vm_ref, settings, CreateNewThread(), "testCanLaunchSecondaryIsolate", {}); ASSERT_TRUE(isolate); ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running); - - latch.Wait(); + child_shutdown_latch.Wait(); // wait for child isolate to shutdown first + latch.Wait(); // wait for last NotifyNative called by main isolate + // root isolate will be auto-shutdown } TEST_F(DartIsolateTest, CanRecieveArguments) { diff --git a/runtime/fixtures/runtime_test.dart b/runtime/fixtures/runtime_test.dart index da3f176c41c97..821e01e8fa433 100644 --- a/runtime/fixtures/runtime_test.dart +++ b/runtime/fixtures/runtime_test.dart @@ -52,8 +52,8 @@ void secondaryIsolateMain(String message) { @pragma('vm:entry-point') void testCanLaunchSecondaryIsolate() { - Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.'); - notifyNative(); + final onExit = RawReceivePort((_) { notifyNative(); }); + Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.', onExit: onExit.sendPort); } @pragma('vm:entry-point') From 849cba4e01c5f2a5b475ea1700b0c4c339f4c5ed Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 18 Sep 2019 15:27:34 -0700 Subject: [PATCH 2/2] ci/format.sh --- runtime/dart_isolate_unittests.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index a59b62353843b..83a140737324b 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -381,8 +381,8 @@ TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) { "testCanLaunchSecondaryIsolate", {}); ASSERT_TRUE(isolate); ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running); - child_shutdown_latch.Wait(); // wait for child isolate to shutdown first - latch.Wait(); // wait for last NotifyNative called by main isolate + child_shutdown_latch.Wait(); // wait for child isolate to shutdown first + latch.Wait(); // wait for last NotifyNative called by main isolate // root isolate will be auto-shutdown }