Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5f3b749

Browse files
authored
Update test to verify that secondary isolate gets shutdown before root isolate exits. (#12342)
* Update secondary-isolate-launch test to verify that secondary isolate gets shutdown before root isolate exits. * ci/format.sh
1 parent 7e087ab commit 5f3b749

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

runtime/dart_isolate.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,10 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair(
774774
void DartIsolate::DartIsolateShutdownCallback(
775775
std::shared_ptr<DartIsolate>* isolate_group_data,
776776
std::shared_ptr<DartIsolate>* isolate_data) {
777+
TRACE_EVENT0("flutter", "DartIsolate::DartIsolateShutdownCallback");
778+
FML_DLOG(INFO) << "DartIsolateShutdownCallback"
779+
<< " isolate_group_data " << isolate_group_data
780+
<< " isolate_data " << isolate_data;
777781
isolate_group_data->get()->OnShutdownCallback();
778782
}
779783

runtime/dart_isolate_unittests.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ TEST_F(DartIsolateTest, CanSaveCompilationTrace) {
360360

361361
TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) {
362362
fml::CountDownLatch latch(3);
363+
fml::AutoResetWaitableEvent child_shutdown_latch;
363364
AddNativeCallback("NotifyNative",
364365
CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
365366
latch.CountDown();
@@ -371,14 +372,18 @@ TEST_F(DartIsolateTest, CanLaunchSecondaryIsolates) {
371372
ASSERT_EQ("Hello from code is secondary isolate.", message);
372373
latch.CountDown();
373374
})));
374-
const auto settings = CreateSettingsForFixture();
375+
auto settings = CreateSettingsForFixture();
376+
settings.isolate_shutdown_callback = [&child_shutdown_latch]() {
377+
child_shutdown_latch.Signal();
378+
};
375379
auto vm_ref = DartVMRef::Create(settings);
376380
auto isolate = RunDartCodeInIsolate(vm_ref, settings, CreateNewThread(),
377381
"testCanLaunchSecondaryIsolate", {});
378382
ASSERT_TRUE(isolate);
379383
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
380-
381-
latch.Wait();
384+
child_shutdown_latch.Wait(); // wait for child isolate to shutdown first
385+
latch.Wait(); // wait for last NotifyNative called by main isolate
386+
// root isolate will be auto-shutdown
382387
}
383388

384389
TEST_F(DartIsolateTest, CanRecieveArguments) {

runtime/fixtures/runtime_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void secondaryIsolateMain(String message) {
5252

5353
@pragma('vm:entry-point')
5454
void testCanLaunchSecondaryIsolate() {
55-
Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.');
56-
notifyNative();
55+
final onExit = RawReceivePort((_) { notifyNative(); });
56+
Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.', onExit: onExit.sendPort);
5757
}
5858

5959
@pragma('vm:entry-point')

0 commit comments

Comments
 (0)