fix(driver): added retry logic to the Futter driver connect call to handle the seemingly random connection failures
This commit is contained in:
parent
6fd30a6492
commit
ff539c0a58
|
@ -1,3 +1,6 @@
|
|||
## [1.1.7+3] - 08/01/2019
|
||||
* Added retry logic to the Futter driver connect call to handle the seemingly random connection failures
|
||||
|
||||
## [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
|
||||
|
||||
|
|
|
@ -59,15 +59,17 @@ class FlutterTestConfiguration extends TestConfiguration {
|
|||
/// Defaults to 2 seconds
|
||||
Duration flutterDriverReconnectionDelay = const Duration(seconds: 2);
|
||||
|
||||
/// The maximum times the flutter driver can try and connect to the running app
|
||||
/// Defaults to 3
|
||||
int flutterDriverMaxConnectionAttemps = 3;
|
||||
|
||||
void setObservatoryDebuggerUri(String uri) => _observatoryDebuggerUri = uri;
|
||||
|
||||
Future<FlutterDriver> createFlutterDriver([String dartVmServiceUrl]) async {
|
||||
dartVmServiceUrl = (dartVmServiceUrl ?? _observatoryDebuggerUri) ??
|
||||
Platform.environment['VM_SERVICE_URL'];
|
||||
|
||||
return await FlutterDriver.connect(
|
||||
dartVmServiceUrl: dartVmServiceUrl,
|
||||
);
|
||||
return await _attemptDriverConnection(dartVmServiceUrl, 1, 3);
|
||||
}
|
||||
|
||||
Future<FlutterWorld> createFlutterWorld(
|
||||
|
@ -101,4 +103,29 @@ class FlutterTestConfiguration extends TestConfiguration {
|
|||
RestartAppStep()
|
||||
]);
|
||||
}
|
||||
|
||||
Future<FlutterDriver> _attemptDriverConnection(
|
||||
String dartVmServiceUrl,
|
||||
int attempt,
|
||||
int maxAttemps,
|
||||
) async {
|
||||
try {
|
||||
return await FlutterDriver.connect(
|
||||
dartVmServiceUrl: dartVmServiceUrl,
|
||||
);
|
||||
} catch (e) {
|
||||
if (attempt > maxAttemps) {
|
||||
rethrow;
|
||||
} else {
|
||||
print(e);
|
||||
await Future<void>.delayed(flutterDriverReconnectionDelay);
|
||||
|
||||
return _attemptDriverConnection(
|
||||
dartVmServiceUrl,
|
||||
attempt + 1,
|
||||
maxAttemps,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue