Skip to content

Commit

Permalink
test: track callback invocations
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and MylesBorins committed Jul 17, 2017
1 parent 0c83573 commit 2aa6828
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions test/sequential/test-net-listen-shared-ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ const assert = require('assert');
const cluster = require('cluster');
const net = require('net');

function noop() {}

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(noop);
const server2 = net.createServer(noop);
const server1 = net.createServer(common.mustNotCall());
const server2 = net.createServer(common.mustNotCall());

server1.on('error', function(err) {
// no errors expected
Expand All @@ -37,10 +35,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 2aa6828

Please sign in to comment.