Skip to content

Commit f7792de

Browse files
TrottMylesBorins
authored andcommitted
test: fix flaky test-net-socket-timeout
The setTimeout() call is unneeded. If the socket never times out, then the test will never finish. Because timers can be unreliable on machines under load, using setTimeout() here effectively creates a race condition. PR-URL: #10172 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
1 parent 3d3263c commit f7792de

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
'use strict';
2-
varcommon=require('../common');
3-
varnet=require('net');
4-
varassert=require('assert');
2+
constcommon=require('../common');
3+
constnet=require('net');
4+
constassert=require('assert');
55

66
// Verify that invalid delays throw
7-
varnoop=function(){};
8-
vars=newnet.Socket();
9-
varnonNumericDelays=['100',true,false,undefined,null,'',{},noop,[]];
10-
varbadRangeDelays=[-0.001,-1,-Infinity,Infinity,NaN];
11-
varvalidDelays=[0,0.001,1,1e6];
7+
constnoop=function(){};
8+
consts=newnet.Socket();
9+
constnonNumericDelays=[
10+
'100',true,false,undefined,null,'',{},noop,[]
11+
];
12+
constbadRangeDelays=[-0.001,-1,-Infinity,Infinity,NaN];
13+
constvalidDelays=[0,0.001,1,1e6];
14+
1215

1316
for(leti=0;i<nonNumericDelays.length;i++){
1417
assert.throws(function(){
@@ -28,15 +31,11 @@ for (let i = 0; i < validDelays.length; i++) {
2831
});
2932
}
3033

31-
varserver=net.Server();
34+
constserver=net.Server();
3235
server.listen(0,common.mustCall(function(){
33-
varsocket=net.createConnection(this.address().port);
34-
socket.setTimeout(100,common.mustCall(function(){
36+
constsocket=net.createConnection(this.address().port);
37+
socket.setTimeout(1,common.mustCall(function(){
3538
socket.destroy();
3639
server.close();
37-
clearTimeout(timer);
3840
}));
39-
vartimer=setTimeout(function(){
40-
process.exit(1);
41-
},common.platformTimeout(200));
4241
}));

0 commit comments

Comments
 (0)