Unverified Commit eb4b6dc9 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Retry Gradle command when failing to download a resource (#50223)

parent da4b5d68
...@@ -108,6 +108,7 @@ final GradleHandledError networkErrorHandler = GradleHandledError( ...@@ -108,6 +108,7 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
'javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake', 'javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake',
'java.net.SocketException: Connection reset', 'java.net.SocketException: Connection reset',
'java.io.FileNotFoundException', 'java.io.FileNotFoundException',
'Gateway Time-out'
]), ]),
handler: ({ handler: ({
String line, String line,
...@@ -116,8 +117,8 @@ final GradleHandledError networkErrorHandler = GradleHandledError( ...@@ -116,8 +117,8 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
bool shouldBuildPluginAsAar, bool shouldBuildPluginAsAar,
}) async { }) async {
globals.printError( globals.printError(
'$warningMark Gradle threw an error while trying to update itself. ' '$warningMark Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
); );
return GradleBuildStatus.retry; return GradleBuildStatus.retry;
}, },
......
...@@ -39,7 +39,7 @@ void main() { ...@@ -39,7 +39,7 @@ void main() {
}); });
group('network errors', () { group('network errors', () {
testUsingContext('throws toolExit if gradle fails while downloading', () async { testUsingContext('retries if gradle fails while downloading', () async {
const String errorMessage = ''' const String errorMessage = '''
Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle.org/distributions/gradle-4.1.1-all.zip Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle.org/distributions/gradle-4.1.1-all.zip
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872)
...@@ -59,13 +59,13 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)'''; ...@@ -59,13 +59,13 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
expect(testLogger.errorText, expect(testLogger.errorText,
contains( contains(
'Gradle threw an error while trying to update itself. ' 'Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
) )
); );
}); });
testUsingContext('throw toolExit if gradle fails downloading with proxy error', () async { testUsingContext('retries if gradle fails downloading with proxy error', () async {
const String errorMessage = ''' const String errorMessage = '''
Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request" Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124) at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124)
...@@ -87,13 +87,13 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)'''; ...@@ -87,13 +87,13 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
expect(testLogger.errorText, expect(testLogger.errorText,
contains( contains(
'Gradle threw an error while trying to update itself. ' 'Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
) )
); );
}); });
testUsingContext('throws toolExit if gradle times out waiting for exclusive access to zip', () async { testUsingContext('retries if gradle times out waiting for exclusive access to zip', () async {
const String errorMessage = ''' const String errorMessage = '''
Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /User/documents/gradle-5.6.2-all.zip Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /User/documents/gradle-5.6.2-all.zip
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:61) at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:61)
...@@ -106,13 +106,13 @@ Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached ...@@ -106,13 +106,13 @@ Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached
expect(testLogger.errorText, expect(testLogger.errorText,
contains( contains(
'Gradle threw an error while trying to update itself. ' 'Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
) )
); );
}); });
testUsingContext('throws toolExit if remote host closes connection', () async { testUsingContext('retries if remote host closes connection', () async {
const String errorMessage = ''' const String errorMessage = '''
Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
...@@ -141,13 +141,13 @@ Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host clos ...@@ -141,13 +141,13 @@ Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host clos
expect(testLogger.errorText, expect(testLogger.errorText,
contains( contains(
'Gradle threw an error while trying to update itself. ' 'Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
) )
); );
}); });
testUsingContext('throws toolExit if file opening fails', () async { testUsingContext('retries if file opening fails', () async {
const String errorMessage = r''' const String errorMessage = r'''
Downloading https://services.gradle.org/distributions/gradle-3.5.0-all.zip Downloading https://services.gradle.org/distributions/gradle-3.5.0-all.zip
Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle-dn.com/distributions/gradle-3.5.0-all.zip Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle-dn.com/distributions/gradle-3.5.0-all.zip
...@@ -168,13 +168,13 @@ Exception in thread "main" java.io.FileNotFoundException: https://downloads.grad ...@@ -168,13 +168,13 @@ Exception in thread "main" java.io.FileNotFoundException: https://downloads.grad
expect(testLogger.errorText, expect(testLogger.errorText,
contains( contains(
'Gradle threw an error while trying to update itself. ' 'Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
) )
); );
}); });
testUsingContext('throws toolExit if the connection is reset', () async { testUsingContext('retries if the connection is reset', () async {
const String errorMessage = ''' const String errorMessage = '''
Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip
Exception in thread "main" java.net.SocketException: Connection reset Exception in thread "main" java.net.SocketException: Connection reset
...@@ -206,8 +206,33 @@ Exception in thread "main" java.net.SocketException: Connection reset ...@@ -206,8 +206,33 @@ Exception in thread "main" java.net.SocketException: Connection reset
expect(testLogger.errorText, expect(testLogger.errorText,
contains( contains(
'Gradle threw an error while trying to update itself. ' 'Gradle threw an error while downloading artifacts from the network. '
'Retrying the update...' 'Retrying to download...'
)
);
});
testUsingContext('retries if Gradle could not get a resource', () async {
const String errorMessage = '''
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
Required by:
project : > com.android.tools.build:gradle:3.3.0
> Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
> Could not parse POM https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom
> Could not resolve net.sf.proguard:proguard-parent:6.0.3.
> Could not resolve net.sf.proguard:proguard-parent:6.0.3.
> Could not get resource 'https://jcenter.bintray.com/net/sf/proguard/proguard-parent/6.0.3/proguard-parent-6.0.3.pom'.
> Could not GET 'https://jcenter.bintray.com/net/sf/proguard/proguard-parent/6.0.3/proguard-parent-6.0.3.pom'. Received status code 504 from server: Gateway Time-out''';
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
) )
); );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment