Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a2aec5e

Browse files
Clement Skaucommit-bot@chromium.org
authored andcommitted
[test] Deflakes, un-excepts http_close_test.
http_close_test was given a test exception in issue 28380. This CL adds Expects to check for the expected number of error on both server and client in testClientCloseWhileSendingRequest. It also moves the server.close() into the server error handler to make sure we don't flakily close the server before all requests are fully sent and received in both ends. This should get rid of: HttpException: Connection closed while receiving data, uri = / #0 _HttpIncoming.listen [...] The modified test has been unflaky across a few hundred test runs locally. A few lints were also fixed in the process such as 'unnecessary new'. Bug: dart-lang/sdk#28380 Change-Id: I3470f70f7965c34f73da71489511e1cb2d1b7e42 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109964 Commit-Queue: Clement Skau <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent dd59b19 commit a2aec5e

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

tests/standalone_2/io/http_close_test.dart

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import "dart:io";
1313
import "dart:typed_data";
1414
import "dart:math";
1515

16-
void testClientAndServerCloseNoListen(int connections) {
16+
testClientAndServerCloseNoListen(int connections) {
1717
HttpServer.bind("127.0.0.1", 0).then((server) {
1818
int closed = 0;
1919
server.listen((request) {
@@ -28,7 +28,7 @@ void testClientAndServerCloseNoListen(int connections) {
2828
}
2929
});
3030
});
31-
var client = new HttpClient();
31+
var client = HttpClient();
3232
for (int i = 0; i < connections; i++) {
3333
client
3434
.get("127.0.0.1", server.port, "/")
@@ -38,10 +38,10 @@ void testClientAndServerCloseNoListen(int connections) {
3838
});
3939
}
4040

41-
void testClientCloseServerListen(int connections) {
41+
testClientCloseServerListen(int connections) {
4242
HttpServer.bind("127.0.0.1", 0).then((server) {
4343
int closed = 0;
44-
void check() {
44+
check() {
4545
closed++;
4646
if (closed == connections * 2) {
4747
Expect.equals(0, server.connectionsInfo().active);
@@ -57,7 +57,7 @@ void testClientCloseServerListen(int connections) {
5757
request.response.done.then((_) => check());
5858
});
5959
});
60-
var client = new HttpClient();
60+
var client = HttpClient();
6161
for (int i = 0; i < connections; i++) {
6262
client
6363
.get("127.0.0.1", server.port, "/")
@@ -67,15 +67,15 @@ void testClientCloseServerListen(int connections) {
6767
});
6868
}
6969

70-
void testClientCloseSendingResponse(int connections) {
71-
var buffer = new Uint8List(64 * 1024);
72-
var rand = new Random();
70+
testClientCloseSendingResponse(int connections) {
71+
var buffer = Uint8List(64 * 1024);
72+
var rand = Random();
7373
for (int i = 0; i < buffer.length; i++) {
7474
buffer[i] = rand.nextInt(256);
7575
}
7676
HttpServer.bind("127.0.0.1", 0).then((server) {
7777
int closed = 0;
78-
void check() {
78+
check() {
7979
closed++;
8080
// Wait for both server and client to see the connections as closed.
8181
if (closed == connections * 2) {
@@ -87,15 +87,15 @@ void testClientCloseSendingResponse(int connections) {
8787
}
8888

8989
server.listen((request) {
90-
var timer = new Timer.periodic(const Duration(milliseconds: 50), (_) {
90+
var timer = Timer.periodic(const Duration(milliseconds: 50), (_) {
9191
request.response.add(buffer);
9292
});
9393
request.response.done.catchError((_) {}).whenComplete(() {
9494
check();
9595
timer.cancel();
9696
});
9797
});
98-
var client = new HttpClient();
98+
var client = HttpClient();
9999
for (int i = 0; i < connections; i++) {
100100
client
101101
.get("127.0.0.1", server.port, "/")
@@ -104,7 +104,7 @@ void testClientCloseSendingResponse(int connections) {
104104
// Ensure we don't accept the response until we have send the entire
105105
// request.
106106
var subscription = response.listen((_) {});
107-
new Timer(const Duration(milliseconds: 20), () {
107+
Timer(const Duration(milliseconds: 20), () {
108108
subscription.cancel();
109109
check();
110110
});
@@ -113,30 +113,37 @@ void testClientCloseSendingResponse(int connections) {
113113
});
114114
}
115115

116-
void testClientCloseWhileSendingRequest(int connections) {
116+
// Closing the request early, before sending the full request payload should
117+
// result in an error on both server and client.
118+
testClientCloseWhileSendingRequest(int connections) {
117119
HttpServer.bind("127.0.0.1", 0).then((server) {
118-
int errors = 0;
120+
int serverErrors = 0;
121+
int clientErrors = 0;
119122
server.listen((request) {
120-
request.listen((_) {});
123+
request.listen((_) {}, onError: (_) {
124+
serverErrors++;
125+
if (serverErrors == connections) {
126+
server.close();
127+
}
128+
});
129+
}, onDone: () {
130+
Expect.equals(connections, clientErrors);
131+
Expect.equals(connections, serverErrors);
121132
});
122-
var client = new HttpClient();
123-
int closed = 0;
133+
var client = HttpClient();
124134
for (int i = 0; i < connections; i++) {
125135
client.post("127.0.0.1", server.port, "/").then((request) {
126136
request.contentLength = 110;
127137
request.write("0123456789");
128138
return request.close();
129139
}).catchError((_) {
130-
closed++;
131-
if (closed == connections) {
132-
server.close();
133-
}
140+
clientErrors++;
134141
});
135142
}
136143
});
137144
}
138145

139-
void main() {
146+
main() {
140147
testClientAndServerCloseNoListen(10);
141148
testClientCloseServerListen(10);
142149
testClientCloseSendingResponse(10);

tests/standalone_2/standalone_2.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Tests using the multitest feature where failure is expected should *also* be
66
# listed in tests/lib/analyzer/analyze_tests.status without the "standalone"
77
# prefix.
8-
io/http_close_test: Pass, RuntimeError # Issue 28380
98
io/non_utf8_directory_test: Skip # Issue 33519. Temp files causing bots to go purple.
109
io/non_utf8_file_test: Skip # Issue 33519. Temp files causing bots to go purple.
1110
io/non_utf8_link_test: Skip # Issue 33519. Temp files causing bots to go purple.

tests/standalone_2/standalone_2_kernel.status

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ io/compile_all_test: Pass
7777
io/compile_all_test: Skip # We do not support --compile-all for precompilation
7878
io/file_fuzz_test: RuntimeError, Pass
7979
io/http_client_connect_test: Skip # Flaky.
80-
io/http_close_test: Crash
8180
io/http_content_length_test: Skip # Flaky.
8281
io/http_proxy_advanced_test: Skip # Flaky
8382
io/http_proxy_test: Skip # Flaky.
@@ -108,9 +107,6 @@ regress_29350_test/none: Pass # Issue 31537
108107
[ $compiler == dartkp && $runtime == dart_precompiled && $system != windows ]
109108
io/namespace_test: RuntimeError
110109

111-
[ $compiler == dartkp && $system == android ]
112-
io/http_close_test: Timeout # Issue 28380
113-
114110
[ $mode == debug && $runtime == vm && ($compiler == dartk || $compiler == dartkb) ]
115111
io/file_lock_test: Slow, Pass
116112
io/raw_socket_test: Crash

0 commit comments

Comments
 (0)