Make sure all isolates start during flutter driver tests. (#65703)
This commit is contained in:
@@ -131,8 +131,22 @@ class VMServiceFlutterDriver extends FlutterDriver {
|
||||
// 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,
|
||||
// such as a debugger, any of which could have resumed the isolate.
|
||||
Future<dynamic> resumeLeniently() {
|
||||
Future<dynamic> resumeLeniently() async {
|
||||
_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) {
|
||||
const int vmMustBePausedCode = 101;
|
||||
if (e is rpc.RpcException && e.code == vmMustBePausedCode) {
|
||||
|
||||
@@ -72,6 +72,10 @@ void main() {
|
||||
connectionLog.add('streamListen');
|
||||
return null;
|
||||
});
|
||||
when(mockPeer.sendRequest('setFlag', any)).thenAnswer((Invocation invocation) {
|
||||
connectionLog.add('setFlag');
|
||||
return null;
|
||||
});
|
||||
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseStartEvent());
|
||||
when(mockIsolate.resume()).thenAnswer((Invocation invocation) {
|
||||
connectionLog.add('resume');
|
||||
@@ -85,9 +89,26 @@ void main() {
|
||||
final FlutterDriver driver = await FlutterDriver.connect(dartVmServiceUrl: '');
|
||||
expect(driver, isNotNull);
|
||||
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 {
|
||||
when(mockIsolate.pauseEvent).thenReturn(MockVMPauseBreakpointEvent());
|
||||
when(mockIsolate.resume()).thenAnswer((Invocation invocation) => Future<dynamic>.value(null));
|
||||
|
||||
Reference in New Issue
Block a user