Skip to content

Commit cd98f5d

Browse files
santigimenoMylesBorins
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: #11790Fixes: #11768 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent 0e13887 commit cd98f5d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,25 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
117117

118118
test(functionserverResponseTimeoutWithPipeline(cb){
119119
letcaughtTimeout='';
120+
letsecReceived=false;
120121
process.on('exit',function(){
121122
assert.strictEqual(caughtTimeout,'/2');
122123
});
123124
constserver=http.createServer(function(req,res){
125+
if(req.url==='/2')
126+
secReceived=true;
124127
consts=res.setTimeout(50,function(){
125128
caughtTimeout+=req.url;
126129
});
127130
assert.ok(sinstanceofhttp.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
constport=server.address().port;

0 commit comments

Comments
 (0)