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: nodejs#11790
Fixes: nodejs#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 italoacasas committed Mar 14, 2017
1 parent 757bf48 commit 734ddbe
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 734ddbe

Please sign in to comment.