From 198e40c9eb88466b4494ef212d2a217cb078ea9a Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 16 Oct 2020 15:07:23 -0700 Subject: [PATCH] [flutter_tools] retry the driver launch of the application up to 3 times. (#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. --- packages/flutter_tools/lib/src/commands/drive.dart | 14 +++++++++++++- .../test/commands.shard/hermetic/drive_test.dart | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 0d59fcb2fe..dacbd0212d 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -246,7 +246,19 @@ class DriveCommand extends RunCommandBase { webUri = residentRunner.uri; } - final LaunchResult result = await appStarter(this, webUri, package, applicationBinary != null); + // Attempt to launch the application up to 3 times, to validate whether it + // is possible to reduce flakiness by hardnening the launch code. + int attempt = 0; + LaunchResult result; + while (attempt < 3) { + // On attempts past 1, assume the application is built correctly and re-use it. + result = await appStarter(this, webUri, package, applicationBinary != null || attempt > 0); + if (result != null) { + break; + } + attempt += 1; + globals.printError('Application failed to start on attempt: $attempt'); + } if (result == null) { throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1); } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart index 0ed3aa0fbf..3e1ff4ea2d 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart @@ -99,7 +99,7 @@ void main() { testUsingContext('returns 1 when app fails to run', () async { testDeviceManager.addDevice(MockDevice()); - appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async => null); + appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async => null, count: 3); final String testApp = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e.dart'); final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');