Skip to content

Commit 198e40c

Browse files
author
Jonah Williams
authored
[flutter_tools] retry the driver launch of the application up to 3 times. (flutter#68334)
We'd like to see how many of these flakes are transient and how many involve the device/machine getting temporarily wedged. Add a retry with no delay to see if it is possible to add sufficient error handling to startApp/installApp to handle this.
1 parent 7b04435 commit 198e40c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/flutter_tools/lib/src/commands/drive.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,19 @@ class DriveCommand extends RunCommandBase {
246246
webUri = residentRunner.uri;
247247
}
248248

249-
final LaunchResult result = await appStarter(this, webUri, package, applicationBinary != null);
249+
// Attempt to launch the application up to 3 times, to validate whether it
250+
// is possible to reduce flakiness by hardnening the launch code.
251+
int attempt = 0;
252+
LaunchResult result;
253+
while (attempt < 3) {
254+
// On attempts past 1, assume the application is built correctly and re-use it.
255+
result = await appStarter(this, webUri, package, applicationBinary != null || attempt > 0);
256+
if (result != null) {
257+
break;
258+
}
259+
attempt += 1;
260+
globals.printError('Application failed to start on attempt: $attempt');
261+
}
250262
if (result == null) {
251263
throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1);
252264
}

packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void main() {
9999

100100
testUsingContext('returns 1 when app fails to run', () async {
101101
testDeviceManager.addDevice(MockDevice());
102-
appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async => null);
102+
appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async => null, count: 3);
103103

104104
final String testApp = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e.dart');
105105
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');

0 commit comments

Comments
 (0)