Skip to content

Commit 2aa6828

Browse files
TrottMylesBorins
authored andcommitted
test: track callback invocations
Use `common.mustCall()` and `common.mustNotCall()` to check that callbacks are invoked the expected number of times in test-net-listen-shared-ports. PR-URL: #13010 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 0c83573 commit 2aa6828

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

test/sequential/test-net-listen-shared-ports.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ const assert = require('assert');
44
const cluster = require('cluster');
55
const net = require('net');
66

7-
function noop() {}
8-
97
if (cluster.isMaster) {
108
const worker1 = cluster.fork();
119

12-
worker1.on('message', function(msg) {
10+
worker1.on('message', common.mustCall(function(msg) {
1311
assert.strictEqual(msg, 'success');
1412
const worker2 = cluster.fork();
1513

16-
worker2.on('message', function(msg) {
14+
worker2.on('message', common.mustCall(function(msg) {
1715
assert.strictEqual(msg, 'server2:EADDRINUSE');
1816
worker1.kill();
1917
worker2.kill();
20-
});
21-
});
18+
}));
19+
}));
2220
} else {
23-
const server1 = net.createServer(noop);
24-
const server2 = net.createServer(noop);
21+
const server1 = net.createServer(common.mustNotCall());
22+
const server2 = net.createServer(common.mustNotCall());
2523

2624
server1.on('error', function(err) {
2725
// no errors expected
@@ -37,10 +35,12 @@ if (cluster.isMaster) {
3735
host: 'localhost',
3836
port: common.PORT,
3937
exclusive: false
40-
}, function() {
41-
server2.listen({port: common.PORT + 1, exclusive: true}, function() {
42-
// the first worker should succeed
43-
process.send('success');
44-
});
45-
});
38+
}, common.mustCall(function() {
39+
server2.listen({port: common.PORT + 1, exclusive: true},
40+
common.mustCall(function() {
41+
// the first worker should succeed
42+
process.send('success');
43+
})
44+
);
45+
}));
4646
}

0 commit comments

Comments
 (0)