Index: tests/standalone/io/http_parser_test.dart |
diff --git a/tests/standalone/io/http_parser_test.dart b/tests/standalone/io/http_parser_test.dart |
index c0d4e1e17c32403b53b5aefa641e04e8de9f6be8..62cdcd5f997fe0253198abcfec4129fe460ab08a 100644 |
--- a/tests/standalone/io/http_parser_test.dart |
+++ b/tests/standalone/io/http_parser_test.dart |
@@ -204,6 +204,24 @@ class HttpParserTest { |
controller = new StreamController(); |
var port = new ReceivePort(); |
controller.stream.pipe(httpParser); |
+ int doneCallCount = 0; |
+ // Called when done parsing entire message and done parsing body. |
+ // Only executed when both are done. |
+ void whenDone() { |
+ doneCallCount++; |
+ if (doneCallCount < 2) return; |
+ Expect.equals(expectedVersion, headers.protocolVersion); |
+ Expect.equals(expectedStatusCode, statusCode); |
+ Expect.equals(expectedReasonPhrase, reasonPhrase); |
+ Expect.isTrue(headersCompleteCalled); |
+ Expect.equals(expectedBytesReceived, bytesReceived); |
+ if (!upgrade) { |
+ Expect.isTrue(dataEndCalled); |
+ if (close) Expect.isTrue(dataEndClose); |
+ Expect.equals(dataEndClose, connectionClose); |
+ } |
+ }; |
+ |
var subscription = httpParser.listen((incoming) { |
port.close(); |
statusCode = incoming.statusCode; |
@@ -230,21 +248,9 @@ class HttpParserTest { |
onDone: () { |
dataEndCalled = true; |
dataEndClose = close; |
+ whenDone(); |
}); |
- }); |
- |
- subscription.onDone(() { |
- Expect.equals(expectedVersion, headers.protocolVersion); |
- Expect.equals(expectedStatusCode, statusCode); |
- Expect.equals(expectedReasonPhrase, reasonPhrase); |
- Expect.isTrue(headersCompleteCalled); |
- Expect.equals(expectedBytesReceived, bytesReceived); |
- if (!upgrade) { |
- Expect.isTrue(dataEndCalled); |
- if (close) Expect.isTrue(dataEndClose); |
- Expect.equals(dataEndClose, connectionClose); |
- } |
- }); |
+ }, onDone: whenDone); |
headersCompleteCalled = false; |
dataEndCalled = false; |