Browse Source

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>
v7.x
Santiago Gimeno 8 years ago
committed by Italo A. Casas
parent
commit
734ddbe77b
No known key found for this signature in database GPG Key ID: 23EFEFE93C4CFFFE
  1. 11
      test/parallel/test-http-set-timeout-server.js

11
test/parallel/test-http-set-timeout-server.js

@ -117,10 +117,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;
});
@ -128,9 +131,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;

Loading…
Cancel
Save