|
3 | 3 | const common = require('../common'); |
4 | 4 | const strictEqual = require('assert').strictEqual; |
5 | 5 |
|
6 | | -function makeAssert(message) { |
7 | | - return function(actual, expected) { |
8 | | - strictEqual(actual, expected, message); |
9 | | - }; |
10 | | -} |
11 | | - |
12 | | - |
13 | 6 | // child_process |
14 | 7 | { |
15 | | - const assert = makeAssert('hasRef() not working on process_wrap'); |
16 | 8 | const spawn = require('child_process').spawn; |
17 | 9 | const cmd = common.isWindows ? 'rundll32' : 'ls'; |
18 | 10 | const cp = spawn(cmd); |
19 | | - assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('hasRef'), true); |
20 | | - assert(cp._handle.hasRef(), true); |
| 11 | + strictEqual(Object.getPrototypeOf(cp._handle).hasOwnProperty('hasRef'), |
| 12 | + true, 'process_wrap: hasRef() missing'); |
| 13 | + strictEqual(cp._handle.hasRef(), |
| 14 | + true, 'process_wrap: not initially refed'); |
21 | 15 | cp.unref(); |
22 | | - assert(cp._handle.hasRef(), false); |
| 16 | + strictEqual(cp._handle.hasRef(), |
| 17 | + false, 'process_wrap: unref() ineffective'); |
23 | 18 | cp.ref(); |
24 | | - assert(cp._handle.hasRef(), true); |
25 | | - cp._handle.close(common.mustCall(() => assert(cp._handle.hasRef(), false))); |
| 19 | + strictEqual(cp._handle.hasRef(), |
| 20 | + true, 'process_wrap: ref() ineffective'); |
| 21 | + cp._handle.close(common.mustCall(() => |
| 22 | + strictEqual(cp._handle.hasRef(), |
| 23 | + false, 'process_wrap: not unrefed on close'))); |
26 | 24 | } |
27 | 25 |
|
28 | 26 |
|
29 | | -// dgram |
| 27 | +// dgram ipv4 |
30 | 28 | { |
31 | | - const assert = makeAssert('hasRef() not working on udp_wrap'); |
32 | 29 | const dgram = require('dgram'); |
33 | | - |
34 | 30 | const sock4 = dgram.createSocket('udp4'); |
35 | | - assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('hasRef'), true); |
36 | | - assert(sock4._handle.hasRef(), true); |
| 31 | + strictEqual(Object.getPrototypeOf(sock4._handle).hasOwnProperty('hasRef'), |
| 32 | + true, 'udp_wrap: ipv4: hasRef() missing'); |
| 33 | + strictEqual(sock4._handle.hasRef(), |
| 34 | + true, 'udp_wrap: ipv4: not initially refed'); |
37 | 35 | sock4.unref(); |
38 | | - assert(sock4._handle.hasRef(), false); |
| 36 | + strictEqual(sock4._handle.hasRef(), |
| 37 | + false, 'udp_wrap: ipv4: unref() ineffective'); |
39 | 38 | sock4.ref(); |
40 | | - assert(sock4._handle.hasRef(), true); |
41 | | - sock4._handle.close( |
42 | | - common.mustCall(() => assert(sock4._handle.hasRef(), false))); |
| 39 | + strictEqual(sock4._handle.hasRef(), |
| 40 | + true, 'udp_wrap: ipv4: ref() ineffective'); |
| 41 | + sock4._handle.close(common.mustCall(() => |
| 42 | + strictEqual(sock4._handle.hasRef(), |
| 43 | + false, 'udp_wrap: ipv4: not unrefed on close'))); |
| 44 | +} |
43 | 45 |
|
| 46 | + |
| 47 | +// dgram ipv6 |
| 48 | +{ |
| 49 | + const dgram = require('dgram'); |
44 | 50 | const sock6 = dgram.createSocket('udp6'); |
45 | | - assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('hasRef'), true); |
46 | | - assert(sock6._handle.hasRef(), true); |
| 51 | + strictEqual(Object.getPrototypeOf(sock6._handle).hasOwnProperty('hasRef'), |
| 52 | + true, 'udp_wrap: ipv6: hasRef() missing'); |
| 53 | + strictEqual(sock6._handle.hasRef(), |
| 54 | + true, 'udp_wrap: ipv6: not initially refed'); |
47 | 55 | sock6.unref(); |
48 | | - assert(sock6._handle.hasRef(), false); |
| 56 | + strictEqual(sock6._handle.hasRef(), |
| 57 | + false, 'udp_wrap: ipv6: unref() ineffective'); |
49 | 58 | sock6.ref(); |
50 | | - assert(sock6._handle.hasRef(), true); |
51 | | - sock6._handle.close( |
52 | | - common.mustCall(() => assert(sock6._handle.hasRef(), false))); |
| 59 | + strictEqual(sock6._handle.hasRef(), |
| 60 | + true, 'udp_wrap: ipv6: ref() ineffective'); |
| 61 | + sock6._handle.close(common.mustCall(() => |
| 62 | + strictEqual(sock6._handle.hasRef(), |
| 63 | + false, 'udp_wrap: ipv6: not unrefed on close'))); |
53 | 64 | } |
54 | 65 |
|
55 | 66 |
|
56 | 67 | // pipe |
57 | 68 | { |
58 | | - const assert = makeAssert('hasRef() not working on pipe_wrap'); |
59 | 69 | const Pipe = process.binding('pipe_wrap').Pipe; |
60 | 70 | const handle = new Pipe(); |
61 | | - assert(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), true); |
62 | | - assert(handle.hasRef(), true); |
| 71 | + strictEqual(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), |
| 72 | + true, 'pipe_wrap: hasRef() missing'); |
| 73 | + strictEqual(handle.hasRef(), |
| 74 | + true, 'pipe_wrap: not initially refed'); |
63 | 75 | handle.unref(); |
64 | | - assert(handle.hasRef(), false); |
| 76 | + strictEqual(handle.hasRef(), |
| 77 | + false, 'pipe_wrap: unref() ineffective'); |
65 | 78 | handle.ref(); |
66 | | - assert(handle.hasRef(), true); |
67 | | - handle.close(common.mustCall(() => assert(handle.hasRef(), false))); |
| 79 | + strictEqual(handle.hasRef(), |
| 80 | + true, 'pipe_wrap: ref() ineffective'); |
| 81 | + handle.close(common.mustCall(() => |
| 82 | + strictEqual(handle.hasRef(), |
| 83 | + false, 'pipe_wrap: not unrefed on close'))); |
68 | 84 | } |
69 | 85 |
|
70 | 86 |
|
71 | 87 | // tcp |
72 | 88 | { |
73 | | - const assert = makeAssert('hasRef() not working on tcp_wrap'); |
74 | 89 | const net = require('net'); |
75 | 90 | const server = net.createServer(() => {}).listen(0); |
76 | | - assert(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), true); |
77 | | - assert(server._handle.hasRef(), true); |
78 | | - assert(server._unref, false); |
| 91 | + strictEqual(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), |
| 92 | + true, 'tcp_wrap: hasRef() missing'); |
| 93 | + strictEqual(server._handle.hasRef(), |
| 94 | + true, 'tcp_wrap: not initially refed'); |
| 95 | + strictEqual(server._unref, |
| 96 | + false, 'tcp_wrap: _unref initially incorrect'); |
79 | 97 | server.unref(); |
80 | | - assert(server._handle.hasRef(), false); |
81 | | - assert(server._unref, true); |
| 98 | + strictEqual(server._handle.hasRef(), |
| 99 | + false, 'tcp_wrap: unref() ineffective'); |
| 100 | + strictEqual(server._unref, |
| 101 | + true, 'tcp_wrap: _unref not updated on unref()'); |
82 | 102 | server.ref(); |
83 | | - assert(server._handle.hasRef(), true); |
84 | | - assert(server._unref, false); |
85 | | - server._handle.close( |
86 | | - common.mustCall(() => assert(server._handle.hasRef(), false))); |
| 103 | + strictEqual(server._handle.hasRef(), |
| 104 | + true, 'tcp_wrap: ref() ineffective'); |
| 105 | + strictEqual(server._unref, |
| 106 | + false, 'tcp_wrap: _unref not updated on ref()'); |
| 107 | + server._handle.close(common.mustCall(() => |
| 108 | + strictEqual(server._handle.hasRef(), |
| 109 | + false, 'tcp_wrap: not unrefed on close'))); |
87 | 110 | } |
88 | 111 |
|
89 | 112 |
|
90 | 113 | // timers |
91 | 114 | { |
92 | | - const assert = makeAssert('hasRef() not working on timer_wrap'); |
93 | 115 | const timer = setTimeout(() => {}, 500); |
94 | 116 | timer.unref(); |
95 | | - assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'), true); |
96 | | - assert(timer._handle.hasRef(), false); |
| 117 | + strictEqual(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'), |
| 118 | + true, 'timer_wrap: hasRef() missing'); |
| 119 | + strictEqual(timer._handle.hasRef(), |
| 120 | + false, 'timer_wrap: unref() ineffective'); |
97 | 121 | timer.ref(); |
98 | | - assert(timer._handle.hasRef(), true); |
99 | | - timer._handle.close( |
100 | | - common.mustCall(() => assert(timer._handle.hasRef(), false))); |
| 122 | + strictEqual(timer._handle.hasRef(), |
| 123 | + true, 'timer_wrap: ref() ineffective'); |
| 124 | + timer._handle.close(common.mustCall(() => |
| 125 | + strictEqual(timer._handle.hasRef(), |
| 126 | + false, 'timer_wrap: not unrefed on close'))); |
101 | 127 | } |
| 128 | + |
| 129 | + |
| 130 | +// see also test/pseudo-tty/test-handle-wrap-isrefed-tty.js |
0 commit comments