Skip to content

Commit be993fc

Browse files
santigimenoMyles Borins
authored andcommitted
test: fix test-net-settimeout flakiness
Wait for the data to be received by the socket before creating the clean-up timer. This way, a possible (though unlikely) `ECONNRESET` error can be avoided. PR-URL: #6166 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 14fcb1d commit be993fc

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎test/parallel/test-net-settimeout.js‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ const assert = require('assert');
88

99
constT=100;
1010

11-
constserver=net.createServer(function(c){
11+
constserver=net.createServer(common.mustCall((c)=>{
1212
c.write('hello');
13-
});
13+
}));
14+
1415
server.listen(common.PORT);
1516

1617
constsocket=net.createConnection(common.PORT,'localhost');
1718

18-
consts=socket.setTimeout(T,function(){
19+
consts=socket.setTimeout(T,()=>{
1920
common.fail('Socket timeout event is not expected to fire');
2021
});
2122
assert.ok(sinstanceofnet.Socket);
2223

23-
socket.setTimeout(0);
24-
25-
setTimeout(function(){
26-
socket.destroy();
27-
server.close();
28-
},T*2);
24+
socket.on('data',common.mustCall(()=>{
25+
setTimeout(function(){
26+
socket.destroy();
27+
server.close();
28+
},T*2);
29+
}));
2930

31+
socket.setTimeout(0);

0 commit comments

Comments
 (0)