Skip to content

Commit 3be1db8

Browse files
committed
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: #11790 Fixes: #11768 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent 1d1dbca commit 3be1db8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,25 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
138138

139139
test(function serverResponseTimeoutWithPipeline(cb) {
140140
let caughtTimeout = '';
141+
let secReceived = false;
141142
process.on('exit', function() {
142143
assert.strictEqual(caughtTimeout, '/2');
143144
});
144145
const server = http.createServer(function(req, res) {
146+
if (req.url === '/2')
147+
secReceived = true;
145148
const s = res.setTimeout(50, function() {
146149
caughtTimeout += req.url;
147150
});
148151
assert.ok(s instanceof http.OutgoingMessage);
149152
if (req.url === '/1') res.end();
150153
});
151154
server.on('timeout', function(socket) {
152-
socket.destroy();
153-
server.close();
154-
cb();
155+
if (secReceived) {
156+
socket.destroy();
157+
server.close();
158+
cb();
159+
}
155160
});
156161
server.listen(common.mustCall(function() {
157162
const port = server.address().port;

0 commit comments

Comments
 (0)