Skip to content

Commit 8c2fb3a

Browse files
speaking-in-codegoderbauer
authored andcommitted
Make sure all isolates start during flutter driver tests. (flutter#65703)
1 parent 173a5d5 commit 8c2fb3a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,22 @@ class VMServiceFlutterDriver extends FlutterDriver {
131131
// Attempts to resume the isolate, but does not crash if it fails because
132132
// the isolate is already resumed. There could be a race with other tools,
133133
// such as a debugger, any of which could have resumed the isolate.
134-
Future<dynamic> resumeLeniently() {
134+
Future<dynamic> resumeLeniently() async {
135135
_log('Attempting to resume isolate');
136+
// Let subsequent isolates start automatically.
137+
try {
138+
final Map<String, dynamic> result =
139+
await connection.peer.sendRequest('setFlag', <String, String>{
140+
'name': 'pause_isolates_on_start',
141+
'value': 'false',
142+
}) as Map<String, dynamic>;
143+
if (result == null || result['type'] != 'Success') {
144+
_log('setFlag failure: $result');
145+
}
146+
} catch (e) {
147+
_log('Failed to set pause_isolates_on_start=false, proceeding. Error: $e');
148+
}
149+
136150
return isolate.resume().catchError((dynamic e) {
137151
const int vmMustBePausedCode = 101;
138152
if (e is rpc.RpcException && e.code == vmMustBePausedCode) {

packages/flutter_driver/test/flutter_driver_test.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ void main() {
7272
connectionLog.add('streamListen');
7373
return null;
7474
});
75+
when(mockPeer.sendRequest('setFlag', any)).thenAnswer((Invocation invocation) {
76+
connectionLog.add('setFlag');
77+
return null;
78+
});
7579
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
7680
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
7781
connectionLog.add('resume');
@@ -85,9 +89,26 @@ void main() {
8589
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
8690
expect(driver, isNotNull);
8791
expectLogContains('Isolate is paused at start');
88-
expect(connectionLog, <String>['resume', 'streamListen', 'onExtensionAdded']);
92+
expect(connectionLog, <String>['setFlag', 'resume', 'streamListen', 'onExtensionAdded']);
8993
});
9094

95+
test('ignores setFlag failure', () async {
96+
when(mockPeer.sendRequest('setFlag', any)).thenThrow(Exception('setFlag failed'));
97+
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
98+
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
99+
return Future<dynamic>.value(null);
100+
});
101+
when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) {
102+
return Stream<String>.fromIterable(<String>['ext.flutter.driver']);
103+
});
104+
105+
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
106+
expectLogContains('Failed to set pause_isolates_on_start=false, proceeding. '
107+
'Error: Exception: setFlag failed');
108+
expect(driver, isNotNull);
109+
});
110+
111+
91112
test('connects to isolate paused mid-flight', () async {
92113
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent());
93114
when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));

0 commit comments

Comments
 (0)