|
1 | 1 | 'use strict'; |
2 | | -varcommon=require('../common'); |
3 | | -varassert=require('assert'); |
4 | | -varnet=require('net'); |
5 | 2 |
|
6 | | -varserver=net.createServer(function(c){ |
| 3 | +// Test that unref'ed sockets with timeouts do not prevent exit. |
| 4 | + |
| 5 | +constcommon=require('../common'); |
| 6 | +constnet=require('net'); |
| 7 | + |
| 8 | +constserver=net.createServer(function(c){ |
7 | 9 | c.write('hello'); |
8 | 10 | c.unref(); |
9 | 11 | }); |
10 | 12 | server.listen(common.PORT); |
11 | 13 | server.unref(); |
12 | 14 |
|
13 | | -vartimedout=false; |
14 | 15 | varconnections=0; |
15 | | -varsockets=[]; |
16 | | -vardelays=[8,5,3,6,2,4]; |
| 16 | +constsockets=[]; |
| 17 | +constdelays=[8,5,3,6,2,4]; |
17 | 18 |
|
18 | 19 | delays.forEach(function(T){ |
19 | | -varsocket=net.createConnection(common.PORT,'localhost'); |
20 | | -socket.on('connect',function(){ |
| 20 | +constsocket=net.createConnection(common.PORT,'localhost'); |
| 21 | +socket.on('connect',common.mustCall(function(){ |
21 | 22 | if(++connections===delays.length){ |
22 | 23 | sockets.forEach(function(s){ |
23 | | -s[0].setTimeout(s[1]*1000,function(){ |
24 | | -timedout=true; |
25 | | -s[0].destroy(); |
| 24 | +s.socket.setTimeout(s.timeout,function(){ |
| 25 | +s.socket.destroy(); |
| 26 | +thrownewError('socket timed out unexpectedly'); |
26 | 27 | }); |
27 | 28 |
|
28 | | -s[0].unref(); |
| 29 | +s.socket.unref(); |
29 | 30 | }); |
30 | 31 | } |
31 | | -}); |
32 | | - |
33 | | -sockets.push([socket,T]); |
34 | | -}); |
| 32 | +})); |
35 | 33 |
|
36 | | -process.on('exit',function(){ |
37 | | -assert.strictEqual(timedout,false, |
38 | | -'Socket timeout should not hold loop open'); |
| 34 | +sockets.push({socket: socket,timeout: T*1000}); |
39 | 35 | }); |
0 commit comments