mirror of
https://github.com/nodejs/node.git
synced 2026-12-04 02:19:15 -05:00
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: https://github.com/nodejs/node/pull/4041 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
This commit is contained in:
1 parent
86b47e8dc0
commit
2ee7853bb7
1 file changed
+8
-4
@@ -13,15 +13,19 @@ var http = require('http');
|
||||
var net = require('net');
|
||||
|
||||
var numRequests = 20;
|
||||
var done = 0;
|
||||
var first = false;
|
||||
|
||||
var server = http.createServer(function(req, res) {
|
||||
res.end('ok');
|
||||
if (!first) {
|
||||
first = true;
|
||||
req.socket.on('close', function() {
|
||||
server.close();
|
||||
});
|
||||
}
|
||||
|
||||
res.end('ok');
|
||||
// Oh no! The connection died!
|
||||
req.socket.destroy();
|
||||
if (++done == numRequests)
|
||||
server.close();
|
||||
});
|
||||
|
||||
server.listen(common.PORT);
|
||||
|
||||
Reference in new issue
Block a user