From 9da0ec2736caecc6b025e8320773d337a096f94a Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Thu, 19 Apr 2018 15:09:07 -0700 Subject: [PATCH] Add a few timeouts to FlutterDriver.connect() (#16762) We're seeing occasional test timeouts trying to call `FlutterDriver.connect()`. Unfortunately, when the test is timed out at the test runner level, you don't get a meaningful test failure or stack trace of where the timeout occurrred. Your test harness also doesn't get to clean up, which can include things like saving the device logs to see what was going on in the device. Thus, this change adds timeouts in the places where we've most commonly observed hangs during tests. --- .../flutter_driver/lib/src/driver/driver.dart | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/flutter_driver/lib/src/driver/driver.dart b/packages/flutter_driver/lib/src/driver/driver.dart index 3380183330..3efe140b17 100644 --- a/packages/flutter_driver/lib/src/driver/driver.dart +++ b/packages/flutter_driver/lib/src/driver/driver.dart @@ -145,9 +145,15 @@ class FlutterDriver { /// /// [logCommunicationToFile] determines whether the command communication /// between the test and the app should be logged to `flutter_driver_commands.log`. - static Future connect({ String dartVmServiceUrl, - bool printCommunication: false, - bool logCommunicationToFile: true }) async { + /// + /// [isolateReadyTimeout] determines how long after we connect to the VM + /// service we will wait for the first isolate to become runnable. + static Future connect({ + String dartVmServiceUrl, + bool printCommunication: false, + bool logCommunicationToFile: true, + Duration isolateReadyTimeout: const Duration(minutes: 1), + }) async { dartVmServiceUrl ??= Platform.environment['VM_SERVICE_URL']; if (dartVmServiceUrl == null) { @@ -164,7 +170,10 @@ class FlutterDriver { final VMServiceClient client = connection.client; final VM vm = await client.getVM(); _log.trace('Looking for the isolate'); - VMIsolate isolate = await vm.isolates.first.loadRunnable(); + VMIsolate isolate = await vm.isolates.first.loadRunnable() + .timeout(isolateReadyTimeout, onTimeout: () { + throw new TimeoutException('Timeout while waiting for the isolate to become runnable'); + }); // TODO(yjbanov): vm_service_client does not support "None" pause event yet. // It is currently reported as null, but we cannot rely on it because @@ -778,8 +787,8 @@ Future _waitAndConnect(String url) async { WebSocket ws1; WebSocket ws2; try { - ws1 = await WebSocket.connect(uri.toString()); - ws2 = await WebSocket.connect(uri.toString()); + ws1 = await WebSocket.connect(uri.toString()).timeout(_kShortTimeout); + ws2 = await WebSocket.connect(uri.toString()).timeout(_kShortTimeout); return new VMServiceClientConnection( new VMServiceClient(new IOWebSocketChannel(ws1).cast()), new rpc.Peer(new IOWebSocketChannel(ws2).cast())..listen()