Improve Gradle retry logic (#96554)

This commit is contained in:
Emmanuel Garcia
2022-02-18 13:54:41 -08:00
committed by GitHub
parent f9921ebcda
commit c8266d34f4
4 changed files with 71 additions and 70 deletions

View File

@@ -138,7 +138,8 @@ void main() {
gradleUtils: FakeGradleUtils(),
platform: FakePlatform(),
);
processManager.addCommand(const FakeCommand(
const FakeCommand fakeCmd = FakeCommand(
command: <String>[
'gradlew',
'-q',
@@ -151,23 +152,15 @@ void main() {
'assembleRelease',
],
exitCode: 1,
stderr: '\nSome gradle message\n'
));
processManager.addCommand(const FakeCommand(
command: <String>[
'gradlew',
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=lib/main.dart',
'-Pbase-application-name=io.flutter.app.FlutterApplication',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=false',
'-Ptree-shake-icons=false',
'assembleRelease',
],
exitCode: 1,
stderr: '\nSome gradle message\n'
));
stderr: '\nSome gradle message\n',
);
processManager.addCommand(fakeCmd);
const int maxRetries = 2;
for (int i = 0; i < maxRetries; i++) {
processManager.addCommand(fakeCmd);
}
fileSystem.directory('android')
.childFile('build.gradle')
@@ -186,6 +179,7 @@ void main() {
int testFnCalled = 0;
await expectLater(() async {
await builder.buildGradleApp(
maxRetries: maxRetries,
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
androidBuildInfo: const AndroidBuildInfo(
BuildInfo(
@@ -221,7 +215,10 @@ void main() {
message: 'Gradle task assembleRelease failed with exit code 1'
));
expect(testFnCalled, equals(2));
expect(logger.statusText, contains('Retrying Gradle Build: #1, wait time: 100ms'));
expect(logger.statusText, contains('Retrying Gradle Build: #2, wait time: 200ms'));
expect(testFnCalled, equals(maxRetries + 1));
expect(testUsage.events, contains(
const TestUsageEvent(
'build',

View File

@@ -102,8 +102,7 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -133,8 +132,7 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -155,8 +153,7 @@ Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -193,8 +190,7 @@ Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host clos
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -223,8 +219,7 @@ Exception in thread "main" java.io.FileNotFoundException: https://downloads.grad
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -264,8 +259,7 @@ Exception in thread "main" java.net.SocketException: Connection reset
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -292,8 +286,7 @@ A problem occurred configuring root project 'android'.
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
@@ -324,8 +317,7 @@ A problem occurred configuring root project 'android'.
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{