From 2aa68282fca6fdd9343163a7a3dbb7cf63e999df Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 12 May 2017 17:01:13 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/13010 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- .../test-net-listen-shared-ports.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/sequential/test-net-listen-shared-ports.js b/test/sequential/test-net-listen-shared-ports.js index 243a96572244d1..001822a475a0da 100644 --- a/test/sequential/test-net-listen-shared-ports.js +++ b/test/sequential/test-net-listen-shared-ports.js @@ -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 @@ -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'); + }) + ); + })); }