From d419ee4d949cd8f60913d06cf67d65dc194f61fe Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 26 Nov 2015 22:34:11 +0100 Subject: [PATCH] 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. --- test/parallel/test-http-many-ended-pipelines.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-http-many-ended-pipelines.js b/test/parallel/test-http-many-ended-pipelines.js index 4e0bc7e8ff736f..604dab7cc2c1d2 100644 --- a/test/parallel/test-http-many-ended-pipelines.js +++ b/test/parallel/test-http-many-ended-pipelines.js @@ -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);