Skip to content

Commit 93c80ea

Browse files
jonahwilliamsmingwandroid
authored andcommitted
Revert "Make sure all isolates start during flutter driver tests. (flutter#61841)" (flutter#62239)
This reverts commit 5fa5701.
1 parent e0cb2a7 commit 93c80ea

File tree

2 files changed

+24
-45
lines changed

2 files changed

+24
-45
lines changed

packages/flutter_driver/lib/src/driver/vmservice_driver.dart

+23-30
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ class VMServiceFlutterDriver extends FlutterDriver {
127127

128128
driver._dartVmReconnectUrl = dartVmServiceUrl;
129129

130+
// Attempts to resume the isolate, but does not crash if it fails because
131+
// the isolate is already resumed. There could be a race with other tools,
132+
// such as a debugger, any of which could have resumed the isolate.
133+
Future<dynamic> resumeLeniently() {
134+
_log('Attempting to resume isolate');
135+
return isolate.resume().catchError((dynamic e) {
136+
const int vmMustBePausedCode = 101;
137+
if (e is rpc.RpcException && e.code == vmMustBePausedCode) {
138+
// No biggie; something else must have resumed the isolate
139+
_log(
140+
'Attempted to resume an already resumed isolate. This may happen '
141+
'when we lose a race with another tool (usually a debugger) that '
142+
'is connected to the same isolate.'
143+
);
144+
} else {
145+
// Failed to resume due to another reason. Fail hard.
146+
throw e;
147+
}
148+
});
149+
}
150+
130151
/// Waits for a signal from the VM service that the extension is registered.
131152
///
132153
/// Looks at the list of loaded extensions for the current [isolateRef], as
@@ -174,26 +195,19 @@ class VMServiceFlutterDriver extends FlutterDriver {
174195
});
175196
}
176197

177-
// The Dart VM may be running with --pause-isolates-on-start.
178-
// Set a listener to unpause new isolates as they are ready to run,
179-
// otherwise they'll hang indefinitely.
180-
client.onIsolateRunnable.listen((VMIsolateRef isolateRef) async {
181-
_resumeLeniently(await isolateRef.load());
182-
});
183-
184198
// Attempt to resume isolate if it was paused
185199
if (isolate.pauseEvent is VMPauseStartEvent) {
186200
_log('Isolate is paused at start.');
187201

188-
await _resumeLeniently(isolate);
202+
await resumeLeniently();
189203
} else if (isolate.pauseEvent is VMPauseExitEvent ||
190204
isolate.pauseEvent is VMPauseBreakpointEvent ||
191205
isolate.pauseEvent is VMPauseExceptionEvent ||
192206
isolate.pauseEvent is VMPauseInterruptedEvent) {
193207
// If the isolate is paused for any other reason, assume the extension is
194208
// already there.
195209
_log('Isolate is paused mid-flight.');
196-
await _resumeLeniently(isolate);
210+
await resumeLeniently();
197211
} else if (isolate.pauseEvent is VMResumeEvent) {
198212
_log('Isolate is not paused. Assuming application is ready.');
199213
} else {
@@ -226,27 +240,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
226240
return driver;
227241
}
228242

229-
/// Attempts to resume the isolate, but does not crash if it fails because
230-
/// the isolate is already resumed. There could be a race with other tools,
231-
/// such as a debugger, any of which could have resumed the isolate.
232-
static Future<dynamic> _resumeLeniently(VMIsolate isolate) {
233-
_log('Attempting to resume isolate');
234-
return isolate.resume().catchError((dynamic e) {
235-
const int vmMustBePausedCode = 101;
236-
if (e is rpc.RpcException && e.code == vmMustBePausedCode) {
237-
// No biggie; something else must have resumed the isolate
238-
_log(
239-
'Attempted to resume an already resumed isolate. This may happen '
240-
'when we lose a race with another tool (usually a debugger) that '
241-
'is connected to the same isolate.'
242-
);
243-
} else {
244-
// Failed to resume due to another reason. Fail hard.
245-
throw e;
246-
}
247-
});
248-
}
249-
250243
static int _nextDriverId = 0;
251244

252245
static const String _flutterExtensionMethodName = 'ext.flutter.driver';

packages/flutter_driver/test/flutter_driver_test.dart

+1-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ void main() {
3535
MockVM mockVM;
3636
MockIsolate mockIsolate;
3737
MockPeer mockPeer;
38-
MockIsolate otherIsolate;
3938

4039
void expectLogContains(String message) {
4140
expect(log, anyElement(contains(message)));
@@ -46,12 +45,8 @@ void main() {
4645
mockClient = MockVMServiceClient();
4746
mockVM = MockVM();
4847
mockIsolate = MockIsolate();
49-
otherIsolate = MockIsolate();
5048
mockPeer = MockPeer();
5149
when(mockClient.getVM()).thenAnswer((_) => Future<MockVM>.value(mockVM));
52-
when(mockClient.onIsolateRunnable).thenAnswer((Invocation invocation) {
53-
return Stream<VMIsolateRef>.fromIterable(<VMIsolateRef>[otherIsolate]);
54-
});
5550
when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[mockIsolate]);
5651
when(mockIsolate.loadRunnable()).thenAnswer((_) => Future<MockIsolate>.value(mockIsolate));
5752
when(mockIsolate.extensionRpcs).thenReturn(<String>[]);
@@ -65,10 +60,6 @@ void main() {
6560
VMServiceClientConnection(mockClient, mockPeer)
6661
);
6762
};
68-
when(otherIsolate.load()).thenAnswer((_) => Future<MockIsolate>.value(otherIsolate));
69-
when(otherIsolate.resume()).thenAnswer((Invocation invocation) {
70-
return Future<dynamic>.value(null);
71-
});
7263
});
7364

7465
tearDown(() async {
@@ -86,20 +77,15 @@ void main() {
8677
connectionLog.add('resume');
8778
return Future<dynamic>.value(null);
8879
});
89-
when(otherIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
9080
when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) {
9181
connectionLog.add('onExtensionAdded');
9282
return Stream<String>.fromIterable(<String>['ext.flutter.driver']);
9383
});
94-
when(otherIsolate.resume()).thenAnswer((Invocation invocation) {
95-
connectionLog.add('other-resume');
96-
return Future<dynamic>.value(null);
97-
});
9884

9985
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
10086
expect(driver, isNotNull);
10187
expectLogContains('Isolate is paused at start');
102-
expect(connectionLog, <String>['resume', 'streamListen', 'other-resume', 'onExtensionAdded']);
88+
expect(connectionLog, <String>['resume', 'streamListen', 'onExtensionAdded']);
10389
});
10490

10591
test('connects to isolate paused mid-flight', () async {

0 commit comments

Comments
 (0)