Skip to content

Commit 3e3f315

Browse files
authored
Fix race in cli_test_driver (#221)
* Fix race in cli_test_driver * Fix race in cli_test_driver Take #2
1 parent de74a73 commit 3e3f315

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/devtools/test/support/cli_test_driver.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'package:devtools/src/vm_service_wrapper.dart';
1010
import 'package:vm_service_lib/vm_service_lib.dart';
1111
import 'package:vm_service_lib/vm_service_lib_io.dart';
1212

13+
import '../integration_tests/integration.dart';
14+
1315
class AppFixture {
1416
AppFixture._(
1517
this.process,
@@ -74,7 +76,7 @@ class CliAppFixture extends AppFixture {
7476
static Future<CliAppFixture> create(String appScriptPath) async {
7577
final Process process = await Process.start(
7678
Platform.resolvedExecutable,
77-
<String>['--observe=0', appScriptPath],
79+
<String>['--observe=0', '--pause-isolates-on-start', appScriptPath],
7880
);
7981

8082
final Stream<String> lines =
@@ -103,6 +105,10 @@ class CliAppFixture extends AppFixture {
103105

104106
final VM vm = await serviceConnection.getVM();
105107

108+
final Isolate isolate =
109+
await _waitForIsolate(serviceConnection, 'PauseStart');
110+
await serviceConnection.resume(isolate.id);
111+
106112
return CliAppFixture._(
107113
appScriptPath,
108114
process,
@@ -113,6 +119,26 @@ class CliAppFixture extends AppFixture {
113119
);
114120
}
115121

122+
static Future<Isolate> _waitForIsolate(
123+
VmServiceWrapper serviceConnection,
124+
String pauseEventKind,
125+
) async {
126+
Isolate foundIsolate;
127+
await waitFor(() async {
128+
final vm = await serviceConnection.getVM();
129+
final isolates = await Future.wait(
130+
vm.isolates.map((ref) => serviceConnection.getIsolate(ref.id)),
131+
);
132+
foundIsolate = isolates.firstWhere(
133+
(isolate) =>
134+
isolate is Isolate && isolate.pauseEvent.kind == pauseEventKind,
135+
orElse: () => null,
136+
);
137+
return foundIsolate != null;
138+
});
139+
return foundIsolate;
140+
}
141+
116142
String get scriptSource {
117143
return File(appScriptPath).readAsStringSync();
118144
}

0 commit comments

Comments
 (0)