mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
retry on HttpException (#34526)
This commit is contained in:
parent
ac2f85bb63
commit
a772d4d314
|
@ -48,6 +48,7 @@ export 'dart:io'
|
|||
HttpClientRequest,
|
||||
HttpClientResponse,
|
||||
HttpClientResponseCompressionState,
|
||||
HttpException,
|
||||
HttpHeaders,
|
||||
HttpRequest,
|
||||
HttpServer,
|
||||
|
|
|
@ -64,6 +64,9 @@ Future<List<int>> _attempt(Uri url, { bool onlyHeaders = false }) async {
|
|||
} on SocketException catch (error) {
|
||||
printTrace('Download error: $error');
|
||||
return null;
|
||||
} on HttpException catch (error) {
|
||||
printTrace('Download error: $error');
|
||||
return null;
|
||||
}
|
||||
final HttpClientResponse response = await request.close();
|
||||
// If we're making a HEAD request, we're only checking to see if the URL is
|
||||
|
|
|
@ -105,6 +105,32 @@ void main() {
|
|||
),
|
||||
});
|
||||
|
||||
testUsingContext('retry from HttpException', () async {
|
||||
String error;
|
||||
FakeAsync().run((FakeAsync time) {
|
||||
fetchUrl(Uri.parse('http://example.invalid/')).then((List<int> value) {
|
||||
error = 'test completed unexpectedly';
|
||||
}, onError: (dynamic exception) {
|
||||
error = 'test failed unexpectedly: $exception';
|
||||
});
|
||||
expect(testLogger.statusText, '');
|
||||
time.elapse(const Duration(milliseconds: 10000));
|
||||
expect(testLogger.statusText,
|
||||
'Download failed -- attempting retry 1 in 1 second...\n'
|
||||
'Download failed -- attempting retry 2 in 2 seconds...\n'
|
||||
'Download failed -- attempting retry 3 in 4 seconds...\n'
|
||||
'Download failed -- attempting retry 4 in 8 seconds...\n',
|
||||
);
|
||||
});
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
expect(error, isNull);
|
||||
expect(testLogger.traceText, contains('Download error: HttpException'));
|
||||
}, overrides: <Type, Generator>{
|
||||
HttpClientFactory: () => () => MockHttpClientThrowing(
|
||||
const io.HttpException('test exception handling'),
|
||||
),
|
||||
});
|
||||
|
||||
testUsingContext('max attempts', () async {
|
||||
String error;
|
||||
List<int> actualResult;
|
||||
|
|
Loading…
Reference in a new issue