mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
Drain socket before throwing (#79289)
This commit is contained in:
parent
5151ea4801
commit
318ff7a0ac
|
@ -96,6 +96,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
|
|||
// The network may be only temporarily unavailable, or the file will be
|
||||
// added on the server later. Avoid having future calls to resolve
|
||||
// fail to check the network again.
|
||||
await response.drain<List<int>>();
|
||||
throw image_provider.NetworkImageLoadException(statusCode: response.statusCode, uri: resolved);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
PaintingBinding.instance!.imageCache!.clearLiveImages();
|
||||
});
|
||||
|
||||
test('Expect thrown exception with statusCode - evicts from cache', () async {
|
||||
test('Expect thrown exception with statusCode - evicts from cache and drains', () async {
|
||||
final int errorStatusCode = HttpStatus.notFound;
|
||||
const String requestUrl = 'foo-url';
|
||||
|
||||
|
@ -68,6 +68,7 @@ void main() {
|
|||
.having((NetworkImageLoadException e) => e.statusCode, 'statusCode', errorStatusCode)
|
||||
.having((NetworkImageLoadException e) => e.uri, 'uri', Uri.base.resolve(requestUrl)),
|
||||
);
|
||||
expect(httpClient.request.response.drained, true);
|
||||
}, skip: isBrowser); // Browser implementation does not use HTTP client but an <img> tag.
|
||||
|
||||
test('Uses the HttpClient provided by debugNetworkImageHttpClientProvider if set', () async {
|
||||
|
@ -234,6 +235,8 @@ class _FakeHttpClientRequest extends Fake implements HttpClientRequest {
|
|||
}
|
||||
|
||||
class _FakeHttpClientResponse extends Fake implements HttpClientResponse {
|
||||
bool drained = false;
|
||||
|
||||
@override
|
||||
int statusCode = HttpStatus.ok;
|
||||
|
||||
|
@ -254,6 +257,12 @@ class _FakeHttpClientResponse extends Fake implements HttpClientResponse {
|
|||
cancelOnError: cancelOnError,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<E> drain<E>([E? futureValue]) async {
|
||||
drained = true;
|
||||
return futureValue ?? <int>[] as E;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeCodec implements Codec {
|
||||
|
|
Loading…
Reference in a new issue