Skip to content

Commit 2ee7853

Browse files
santigimenoMyles Borins
authored and
Myles Borins
committed
test: fix http-many-ended-pipelines flakiness
It can happen that the HTTP connection is closed before the server has received all the requests, thus the server close condition is never reached. To solve this, close the server when the socket is fully closed. PR-URL: #4041 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent 86b47e8 commit 2ee7853

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/parallel/test-http-many-ended-pipelines.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ var http = require('http');
1313
var net = require('net');
1414

1515
var numRequests = 20;
16-
var done = 0;
16+
var first = false;
1717

1818
var server = http.createServer(function(req, res) {
19-
res.end('ok');
19+
if (!first) {
20+
first = true;
21+
req.socket.on('close', function() {
22+
server.close();
23+
});
24+
}
2025

26+
res.end('ok');
2127
// Oh no! The connection died!
2228
req.socket.destroy();
23-
if (++done == numRequests)
24-
server.close();
2529
});
2630

2731
server.listen(common.PORT);

0 commit comments

Comments
 (0)