Skip to content

Commit 90c4c84

Browse files
committed
api tests: Have FakeHttpClient.send enqueue response handling in a new task
The Future returned by FakeHttpClient.send is created with either Future.value or Future.error, which means it'll complete in a *microtask*: https://web.archive.org/web/20170704074724/https://webdev.dartlang.org/articles/performance/event-loop#event-queue-new-future That's too soon, as a simulation for a real API response coming over an HTTP connection. In the live code that this simulates, the Future completes in a new task. So, mimic that behavior.
1 parent 32927ff commit 90c4c84

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/api/fake_api.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ class FakeHttpClient extends http.BaseClient {
7373
lastRequest = request;
7474
switch (response) {
7575
case _PreparedException(:var exception):
76-
return Future.error(exception);
76+
return Future(() => throw exception);
7777
case _PreparedSuccess(:var bytes, :var httpStatus):
7878
final byteStream = http.ByteStream.fromBytes(bytes);
79-
return Future.value(http.StreamedResponse(
79+
return Future(() => http.StreamedResponse(
8080
byteStream, httpStatus, request: request));
8181
}
8282
}

0 commit comments

Comments
 (0)