Skip to content

Commit c81f710

Browse files
insightfulsBen Schmidt
authored andcommitted
test: improve failure messages in isrefed tests
1 parent 18d9be2 commit c81f710

File tree

2 files changed

+88
-66
lines changed

2 files changed

+88
-66
lines changed

test/parallel/test-handle-wrap-isrefed.js

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,127 @@
33
const common = require('../common');
44
const strictEqual = require('assert').strictEqual;
55

6-
function makeAssert(message) {
7-
return function(actual, expected) {
8-
strictEqual(actual, expected, message);
9-
};
10-
}
11-
12-
136
// child_process
147
{
15-
const assert = makeAssert('hasRef() not working on process_wrap');
168
const spawn = require('child_process').spawn;
179
const cmd = common.isWindows ? 'rundll32' : 'ls';
1810
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');
2115
cp.unref();
22-
assert(cp._handle.hasRef(), false);
16+
strictEqual(cp._handle.hasRef(),
17+
false, 'process_wrap: unref() ineffective');
2318
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')));
2624
}
2725

2826

29-
// dgram
27+
// dgram ipv4
3028
{
31-
const assert = makeAssert('hasRef() not working on udp_wrap');
3229
const dgram = require('dgram');
33-
3430
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');
3735
sock4.unref();
38-
assert(sock4._handle.hasRef(), false);
36+
strictEqual(sock4._handle.hasRef(),
37+
false, 'udp_wrap: ipv4: unref() ineffective');
3938
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+
}
45+
4346

47+
// dgram ipv6
48+
{
49+
const dgram = require('dgram');
4450
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');
4755
sock6.unref();
48-
assert(sock6._handle.hasRef(), false);
56+
strictEqual(sock6._handle.hasRef(),
57+
false, 'udp_wrap: ipv6: unref() ineffective');
4958
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')));
5364
}
5465

5566

5667
// pipe
5768
{
58-
const assert = makeAssert('hasRef() not working on pipe_wrap');
5969
const Pipe = process.binding('pipe_wrap').Pipe;
6070
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');
6375
handle.unref();
64-
assert(handle.hasRef(), false);
76+
strictEqual(handle.hasRef(),
77+
false, 'pipe_wrap: unref() ineffective');
6578
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')));
6884
}
6985

7086

7187
// tcp
7288
{
73-
const assert = makeAssert('hasRef() not working on tcp_wrap');
7489
const net = require('net');
7590
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');
7997
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()');
82102
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')));
87110
}
88111

89112

90113
// timers
91114
{
92-
const assert = makeAssert('hasRef() not working on timer_wrap');
93115
const timer = setTimeout(() => {}, 500);
94116
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');
97121
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')));
101127
}
102128

103129

test/pseudo-tty/test-handle-wrap-isrefed-tty.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@
44

55
const common = require('../common');
66
const strictEqual = require('assert').strictEqual;
7-
8-
function makeAssert(message) {
9-
return function(actual, expected) {
10-
strictEqual(actual, expected, message);
11-
};
12-
}
13-
14-
const assert = makeAssert('hasRef() not working on tty_wrap');
15-
167
const ReadStream = require('tty').ReadStream;
178
const tty = new ReadStream(0);
189
const isTTY = process.binding('tty_wrap').isTTY;
19-
assert(isTTY(0), true);
20-
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true);
21-
assert(tty._handle.hasRef(), true);
10+
strictEqual(isTTY(0), true, 'tty_wrap: stdin is not a TTY');
11+
strictEqual(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'),
12+
true, 'tty_wrap: hasRef() missing');
13+
strictEqual(tty._handle.hasRef(),
14+
true, 'tty_wrap: not initially refed');
2215
tty.unref();
23-
assert(tty._handle.hasRef(), false);
16+
strictEqual(tty._handle.hasRef(),
17+
false, 'tty_wrap: unref() ineffective');
2418
tty.ref();
25-
assert(tty._handle.hasRef(), true);
26-
tty._handle.close(
27-
common.mustCall(() => assert(tty._handle.hasRef(), false)));
19+
strictEqual(tty._handle.hasRef(),
20+
true, 'tty_wrap: ref() ineffective');
21+
tty._handle.close(common.mustCall(() =>
22+
strictEqual(tty._handle.hasRef(),
23+
false, 'tty_wrap: not unrefed on close')));

0 commit comments

Comments
 (0)