Skip to content

Commit

Permalink
test: fix flaky test-http-set-timeout-server
Browse files Browse the repository at this point in the history
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: #11790
Fixes: #11768
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information
santigimeno authored and MylesBorins committed Apr 19, 2017
1 parent 0e13887 commit cd98f5d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions test/parallel/test-http-set-timeout-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,25 @@ 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;
});
assert.ok(s instanceof http.OutgoingMessage);
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;
Expand Down

0 comments on commit cd98f5d

Please sign in to comment.