Skip to content

Commit 1860eae

Browse files
Trottrvagg
authored andcommitted
test: refactor test-net-settimeout
test-net-settimeout is unnecessarily complex. This change simplifies it. PR-URL: #4799 Reviewed-By: Brian White <[email protected]> Reviewed-By: Johan Bergström <[email protected]>
1 parent fa0457e commit 1860eae

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,28 @@
22
// This example sets a timeout then immediately attempts to disable the timeout
33
// https://github.com/joyent/node/pull/2245
44

5-
varcommon=require('../common');
6-
varnet=require('net');
7-
varassert=require('assert');
5+
constcommon=require('../common');
6+
constnet=require('net');
7+
constassert=require('assert');
88

9-
varT=100;
9+
constT=100;
1010

11-
varserver=net.createServer(function(c){
11+
constserver=net.createServer(function(c){
1212
c.write('hello');
1313
});
1414
server.listen(common.PORT);
1515

16-
varkillers=[0];
16+
constsocket=net.createConnection(common.PORT,'localhost');
1717

18-
varleft=killers.length;
19-
killers.forEach(function(killer){
20-
varsocket=net.createConnection(common.PORT,'localhost');
18+
consts=socket.setTimeout(T,function(){
19+
common.fail('Socket timeout event is not expected to fire');
20+
});
21+
assert.ok(sinstanceofnet.Socket);
2122

22-
vars=socket.setTimeout(T,function(){
23-
socket.destroy();
24-
if(--left===0)server.close();
25-
assert.ok(killer!==0);
26-
clearTimeout(timeout);
27-
});
28-
assert.ok(sinstanceofnet.Socket);
23+
socket.setTimeout(0);
2924

30-
socket.setTimeout(killer);
25+
setTimeout(function(){
26+
socket.destroy();
27+
server.close();
28+
},T*2);
3129

32-
vartimeout=setTimeout(function(){
33-
socket.destroy();
34-
if(--left===0)server.close();
35-
assert.ok(killer===0);
36-
},T*2);
37-
});

0 commit comments

Comments
(0)