Skip to content
Permalink
Browse files

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 <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information...
Trott authored and addaleax committed May 13, 2017
1 parent 28ddac2 commit 7e5ed8bad9b135c710a6623ed34e2c78de3b53de
Showing with 14 additions and 12 deletions.
  1. +14 −12 test/sequential/test-net-listen-shared-ports.js
@@ -28,19 +28,19 @@ const net = require('net');
if (cluster.isMaster) {
const worker1 = cluster.fork();

worker1.on('message', function(msg) {
worker1.on('message', common.mustCall(function(msg) {
assert.strictEqual(msg, 'success');
const worker2 = cluster.fork();

worker2.on('message', function(msg) {
worker2.on('message', common.mustCall(function(msg) {
assert.strictEqual(msg, 'server2:EADDRINUSE');
worker1.kill();
worker2.kill();
});
});
}));
}));
} else {
const server1 = net.createServer(common.noop);
const server2 = net.createServer(common.noop);
const server1 = net.createServer(common.mustNotCall());
const server2 = net.createServer(common.mustNotCall());

server1.on('error', function(err) {
// no errors expected
@@ -56,10 +56,12 @@ if (cluster.isMaster) {
host: 'localhost',
port: common.PORT,
exclusive: false
}, function() {
server2.listen({port: common.PORT + 1, exclusive: true}, function() {
// the first worker should succeed
process.send('success');
});
});
}, common.mustCall(function() {
server2.listen({port: common.PORT + 1, exclusive: true},
common.mustCall(function() {
// the first worker should succeed
process.send('success');
})
);
}));
}

0 comments on commit 7e5ed8b

Please sign in to comment.
You can’t perform that action at this time.