Skip to content

Commit 734ddbe

Browse files
santigimenoitaloacasas
authored andcommitted
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 757bf48 commit 734ddbe

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
@@ -117,20 +117,25 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
117117

118118
test(function serverResponseTimeoutWithPipeline(cb) {
119119
let caughtTimeout = '';
120+
let secReceived = false;
120121
process.on('exit', function() {
121122
assert.strictEqual(caughtTimeout, '/2');
122123
});
123124
const server = http.createServer(function(req, res) {
125+
if (req.url === '/2')
126+
secReceived = true;
124127
const s = res.setTimeout(50, function() {
125128
caughtTimeout += req.url;
126129
});
127130
assert.ok(s instanceof http.OutgoingMessage);
128131
if (req.url === '/1') res.end();
129132
});
130133
server.on('timeout', function(socket) {
131-
socket.destroy();
132-
server.close();
133-
cb();
134+
if (secReceived) {
135+
socket.destroy();
136+
server.close();
137+
cb();
138+
}
134139
});
135140
server.listen(common.mustCall(function() {
136141
const port = server.address().port;

0 commit comments

Comments
 (0)