Unverified Commit 7a4d8e19 authored by Brian Eaton's avatar Brian Eaton Committed by GitHub

Make sure all isolates start during flutter driver tests. (#65703)

parent 4253e42b
...@@ -131,8 +131,22 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -131,8 +131,22 @@ class VMServiceFlutterDriver extends FlutterDriver {
// Attempts to resume the isolate, but does not crash if it fails because // Attempts to resume the isolate, but does not crash if it fails because
// the isolate is already resumed. There could be a race with other tools, // the isolate is already resumed. There could be a race with other tools,
// such as a debugger, any of which could have resumed the isolate. // such as a debugger, any of which could have resumed the isolate.
Future<dynamic> resumeLeniently() { Future<dynamic> resumeLeniently() async {
_log('Attempting to resume isolate'); _log('Attempting to resume isolate');
// Let subsequent isolates start automatically.
try {
final Map<String, dynamic> result =
await connection.peer.sendRequest('setFlag', <String, String>{
'name': 'pause_isolates_on_start',
'value': 'false',
}) as Map<String, dynamic>;
if (result == null || result['type'] != 'Success') {
_log('setFlag failure: $result');
}
} catch (e) {
_log('Failed to set pause_isolates_on_start=false, proceeding. Error: $e');
}
return isolate.resume().catchError((dynamic e) { return isolate.resume().catchError((dynamic e) {
const int vmMustBePausedCode = 101; const int vmMustBePausedCode = 101;
if (e is rpc.RpcException && e.code == vmMustBePausedCode) { if (e is rpc.RpcException && e.code == vmMustBePausedCode) {
......
...@@ -72,6 +72,10 @@ void main() { ...@@ -72,6 +72,10 @@ void main() {
connectionLog.add('streamListen'); connectionLog.add('streamListen');
return null; return null;
}); });
when(mockPeer.sendRequest('setFlag', any)).thenAnswer((Invocation invocation) {
connectionLog.add('setFlag');
return null;
});
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent()); when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
when(mockIsolate.resume()).thenAnswer((Invocation invocation) { when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
connectionLog.add('resume'); connectionLog.add('resume');
...@@ -85,9 +89,26 @@ void main() { ...@@ -85,9 +89,26 @@ void main() {
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: ''); final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expect(driver, isNotNull); expect(driver, isNotNull);
expectLogContains('Isolate is paused at start'); expectLogContains('Isolate is paused at start');
expect(connectionLog, <String>['resume', 'streamListen', 'onExtensionAdded']); expect(connectionLog, <String>['setFlag', 'resume', 'streamListen', 'onExtensionAdded']);
}); });
test('ignores setFlag failure', () async {
when(mockPeer.sendRequest('setFlag', any)).thenThrow(Exception('setFlag failed'));
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
return Future<dynamic>.value(null);
});
when(mockIsolate.onExtensionAdded).thenAnswer((Invocation invocation) {
return Stream<String>.fromIterable(<String>['ext.flutter.driver']);
});
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
expectLogContains('Failed to set pause_isolates_on_start=false, proceeding. '
'Error: Exception: setFlag failed');
expect(driver, isNotNull);
});
test('connects to isolate paused mid-flight', () async { test('connects to isolate paused mid-flight', () async {
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent()); when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent());
when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null)); when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment