From 470a17cf56491e2455e5aa56e6a16ee5c2055bd2 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Fri, 10 Mar 2017 12:13:49 +0100 Subject: [PATCH] test: fix flaky test-http-set-timeout-server It can happen that the connection and server is closed before the second reponse has been processed by server. In this case, the `res.setTimeout()` callback will never be called causing the test to fail. Fix this by only closing the connection and server when the 2nd has been received. PR-URL: https://github.com/nodejs/node/pull/11790 Fixes: https://github.com/nodejs/node/issues/11768 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock --- test/parallel/test-http-set-timeout-server.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http-set-timeout-server.js b/test/parallel/test-http-set-timeout-server.js index 43b74069ac066d..0420a21cb4c4d4 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -138,10 +138,13 @@ test(function serverRequestNotTimeoutAfterEnd(cb) { test(function serverResponseTimeoutWithPipeline(cb) { let caughtTimeout = ''; + let secReceived = false; process.on('exit', function() { assert.strictEqual(caughtTimeout, '/2'); }); const server = http.createServer(function(req, res) { + if (req.url === '/2') + secReceived = true; const s = res.setTimeout(50, function() { caughtTimeout += req.url; }); @@ -149,9 +152,11 @@ test(function serverResponseTimeoutWithPipeline(cb) { if (req.url === '/1') res.end(); }); server.on('timeout', function(socket) { - socket.destroy(); - server.close(); - cb(); + if (secReceived) { + socket.destroy(); + server.close(); + cb(); + } }); server.listen(common.mustCall(function() { const port = server.address().port;