From 6fd30a64927d2c14398572b2b4ca70189a321e2f Mon Sep 17 00:00:00 2001 From: Jon Samwell Date: Tue, 7 Jan 2020 17:02:13 +1100 Subject: [PATCH] fix(driver): increased the Flutter driver reconnection delay to try and overcome some driver to app connection issues on slower machines --- CHANGELOG.md | 3 +++ lib/src/flutter/flutter_run_process_handler.dart | 7 ++++++- lib/src/flutter/flutter_test_configuration.dart | 7 ++++++- lib/src/flutter/flutter_world.dart | 2 +- lib/src/flutter/hooks/app_runner_hook.dart | 1 + pubspec.yaml | 2 +- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6800ae5..2939cd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.1.7+2] - 07/01/2019 +* Increased the Flutter driver reconnection delay to try and overcome some driver to app connection issues on slower machines + ## [1.1.7+1] - 07/01/2019 * Ensured when the Flutter driver is closed it cannot throw an unhandled exception causing the test run the stop * Updated Gherkin library version diff --git a/lib/src/flutter/flutter_run_process_handler.dart b/lib/src/flutter/flutter_run_process_handler.dart index 8e3ed5c..a977554 100644 --- a/lib/src/flutter/flutter_run_process_handler.dart +++ b/lib/src/flutter/flutter_run_process_handler.dart @@ -41,6 +41,7 @@ class FlutterRunProcessHandler extends ProcessHandler { String _appTarget; String _buildFlavor; String _deviceTargetId; + Duration _driverConnectionDelay = const Duration(seconds: 2); String currentObservatoryUri; void setLogFlutterProcessOutput(bool logFlutterProcessOutput) { @@ -51,6 +52,10 @@ class FlutterRunProcessHandler extends ProcessHandler { _appTarget = targetPath; } + void setDriverConnectionDelay(Duration duration) { + _driverConnectionDelay = duration ?? _driverConnectionDelay; + } + void setWorkingDirectory(String workingDirectory) { _workingDirectory = workingDirectory; } @@ -146,7 +151,7 @@ class FlutterRunProcessHandler extends ProcessHandler { // it seems we need a small delay here otherwise the flutter driver fails to // consistently connect - await Future.delayed(Duration(seconds: 1)); + await Future.delayed(_driverConnectionDelay); return Future.value(true); } diff --git a/lib/src/flutter/flutter_test_configuration.dart b/lib/src/flutter/flutter_test_configuration.dart index 5ba990e..0453c59 100644 --- a/lib/src/flutter/flutter_test_configuration.dart +++ b/lib/src/flutter/flutter_test_configuration.dart @@ -52,7 +52,12 @@ class FlutterTestConfiguration extends TestConfiguration { /// Duration to wait for Flutter to build and start the app on the target device /// Slower machine may take longer to build and run a large app /// Defaults to 90 seconds - Duration flutterBuildTimeout = Duration(seconds: 90); + Duration flutterBuildTimeout = const Duration(seconds: 90); + + /// Duration to wait before reconnecting the Flutter driver to the app. + /// On slower machines the app might not be in a state where the driver can successfully connect immediately + /// Defaults to 2 seconds + Duration flutterDriverReconnectionDelay = const Duration(seconds: 2); void setObservatoryDebuggerUri(String uri) => _observatoryDebuggerUri = uri; diff --git a/lib/src/flutter/flutter_world.dart b/lib/src/flutter/flutter_world.dart index e6f25a2..b6205ed 100644 --- a/lib/src/flutter/flutter_world.dart +++ b/lib/src/flutter/flutter_world.dart @@ -49,7 +49,7 @@ class FlutterWorld extends World { await _driver.close(); } } catch (e, st) { - print('Error closing Flutter driver:\n\n`${e}`\n\n${st}'); + print('Error closing Flutter driver:\n\n`$e`\n\n$st'); } finally { _driver = null; } diff --git a/lib/src/flutter/hooks/app_runner_hook.dart b/lib/src/flutter/hooks/app_runner_hook.dart index a219d11..c554646 100644 --- a/lib/src/flutter/hooks/app_runner_hook.dart +++ b/lib/src/flutter/hooks/app_runner_hook.dart @@ -62,6 +62,7 @@ class FlutterAppRunnerHook extends Hook { ..setLogFlutterProcessOutput(config.logFlutterProcessOutput) ..setVerboseFluterlogs(config.verboseFlutterProcessLogs) ..setApplicationTargetFile(config.targetAppPath) + ..setDriverConnectionDelay(config.flutterDriverReconnectionDelay) ..setWorkingDirectory(config.targetAppWorkingDirecotry) ..setBuildRequired(haveRunFirstScenario ? false : config.build) ..setBuildFlavor(config.buildFlavor) diff --git a/pubspec.yaml b/pubspec.yaml index cd6a141..421b55f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_gherkin description: A Gherkin / Cucumber parser and test runner for Dart and Flutter -version: 1.1.7+1 +version: 1.1.7+2 author: Jon Samwell homepage: https://github.com/jonsamwell/flutter_gherkin