@@ -127,6 +127,27 @@ class VMServiceFlutterDriver extends FlutterDriver {
127
127
128
128
driver._dartVmReconnectUrl = dartVmServiceUrl;
129
129
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
+
130
151
/// Waits for a signal from the VM service that the extension is registered.
131
152
///
132
153
/// Looks at the list of loaded extensions for the current [isolateRef] , as
@@ -174,26 +195,19 @@ class VMServiceFlutterDriver extends FlutterDriver {
174
195
});
175
196
}
176
197
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
-
184
198
// Attempt to resume isolate if it was paused
185
199
if (isolate.pauseEvent is VMPauseStartEvent ) {
186
200
_log ('Isolate is paused at start.' );
187
201
188
- await _resumeLeniently (isolate );
202
+ await resumeLeniently ( );
189
203
} else if (isolate.pauseEvent is VMPauseExitEvent ||
190
204
isolate.pauseEvent is VMPauseBreakpointEvent ||
191
205
isolate.pauseEvent is VMPauseExceptionEvent ||
192
206
isolate.pauseEvent is VMPauseInterruptedEvent ) {
193
207
// If the isolate is paused for any other reason, assume the extension is
194
208
// already there.
195
209
_log ('Isolate is paused mid-flight.' );
196
- await _resumeLeniently (isolate );
210
+ await resumeLeniently ( );
197
211
} else if (isolate.pauseEvent is VMResumeEvent ) {
198
212
_log ('Isolate is not paused. Assuming application is ready.' );
199
213
} else {
@@ -226,27 +240,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
226
240
return driver;
227
241
}
228
242
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
-
250
243
static int _nextDriverId = 0 ;
251
244
252
245
static const String _flutterExtensionMethodName = 'ext.flutter.driver' ;
0 commit comments