From ef3698cad867c1bd0d5505c76451bbf6b3d0fd31 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 14 Jun 2017 14:59:26 -0400 Subject: [PATCH] test: refactor test-cluster-worker-isconnected.js PR-URL: https://github.com/nodejs/node/pull/13685 Reviewed-By: Refael Ackermann Reviewed-By: Luigi Pinca Reviewed-By: David Cai Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell --- .../test-cluster-worker-isconnected.js | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/test/parallel/test-cluster-worker-isconnected.js b/test/parallel/test-cluster-worker-isconnected.js index 8b2ad865899c60..a0ada77bd023b1 100644 --- a/test/parallel/test-cluster-worker-isconnected.js +++ b/test/parallel/test-cluster-worker-isconnected.js @@ -1,38 +1,30 @@ 'use strict'; -require('../common'); +const common = require('../common'); const cluster = require('cluster'); const assert = require('assert'); if (cluster.isMaster) { const worker = cluster.fork(); - assert.ok(worker.isConnected(), - 'isConnected() should return true as soon as the worker has ' + - 'been created.'); + assert.strictEqual(worker.isConnected(), true); - worker.on('disconnect', function() { - assert.ok(!worker.isConnected(), - 'After a disconnect event has been emitted, ' + - 'isConncted should return false'); - }); + worker.on('disconnect', common.mustCall(() => { + assert.strictEqual(worker.isConnected(), false); + })); worker.on('message', function(msg) { if (msg === 'readyToDisconnect') { worker.disconnect(); } }); - } else { - assert.ok(cluster.worker.isConnected(), - 'isConnected() should return true from within a worker at all ' + - 'times.'); + function assertNotConnected() { + assert.strictEqual(cluster.worker.isConnected(), false); + } - cluster.worker.process.on('disconnect', function() { - assert.ok(!cluster.worker.isConnected(), - 'isConnected() should return false from within a worker ' + - 'after its underlying process has been disconnected from ' + - 'the master'); - }); + assert.strictEqual(cluster.worker.isConnected(), true); + cluster.worker.on('disconnect', common.mustCall(assertNotConnected)); + cluster.worker.process.on('disconnect', common.mustCall(assertNotConnected)); process.send('readyToDisconnect'); }