Unverified Commit 318ff7a0 authored by Dan Field's avatar Dan Field Committed by GitHub

Drain socket before throwing (#79289)

parent 5151ea48
......@@ -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 {
......
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