diff options
author | Santiago Gimeno <santiago.gimeno@gmail.com> | 2017-03-10 12:13:49 +0100 |
---|---|---|
committer | Santiago Gimeno <santiago.gimeno@gmail.com> | 2017-03-14 09:56:23 +0100 |
commit | 3be1db8702f0e2737bf0fceedd4a58b3ddd4ce99 (patch) | |
tree | 7bcaf782761bf19177ac0069b79c1c24501d9142 /test/parallel/test-http-set-timeout-server.js | |
parent | 1d1dbcafa8a2deca2417e976650d0ad7a01a38c2 (diff) | |
download | node-new-3be1db8702f0e2737bf0fceedd4a58b3ddd4ce99.tar.gz |
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 <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Diffstat (limited to 'test/parallel/test-http-set-timeout-server.js')
-rw-r--r-- | test/parallel/test-http-set-timeout-server.js | 11 |
1 files 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 43b74069ac..0420a21cb4 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; |