Browse Source

test: refactor test-cluster-worker-isconnected.js

PR-URL: https://github.com/nodejs/node/pull/13685
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: David Cai <davidcai1993@yahoo.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
cjihrig 8 years ago
committed by James M Snell
parent
commit
06ca205719
  1. 30
      test/parallel/test-cluster-worker-isconnected.js

30
test/parallel/test-cluster-worker-isconnected.js

@ -1,38 +1,30 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const cluster = require('cluster'); const cluster = require('cluster');
const assert = require('assert'); const assert = require('assert');
if (cluster.isMaster) { if (cluster.isMaster) {
const worker = cluster.fork(); const worker = cluster.fork();
assert.ok(worker.isConnected(), assert.strictEqual(worker.isConnected(), true);
'isConnected() should return true as soon as the worker has ' +
'been created.');
worker.on('disconnect', function() { worker.on('disconnect', common.mustCall(() => {
assert.ok(!worker.isConnected(), assert.strictEqual(worker.isConnected(), false);
'After a disconnect event has been emitted, ' + }));
'isConncted should return false');
});
worker.on('message', function(msg) { worker.on('message', function(msg) {
if (msg === 'readyToDisconnect') { if (msg === 'readyToDisconnect') {
worker.disconnect(); worker.disconnect();
} }
}); });
} else { } else {
assert.ok(cluster.worker.isConnected(), function assertNotConnected() {
'isConnected() should return true from within a worker at all ' + assert.strictEqual(cluster.worker.isConnected(), false);
'times.'); }
cluster.worker.process.on('disconnect', function() { assert.strictEqual(cluster.worker.isConnected(), true);
assert.ok(!cluster.worker.isConnected(), cluster.worker.on('disconnect', common.mustCall(assertNotConnected));
'isConnected() should return false from within a worker ' + cluster.worker.process.on('disconnect', common.mustCall(assertNotConnected));
'after its underlying process has been disconnected from ' +
'the master');
});
process.send('readyToDisconnect'); process.send('readyToDisconnect');
} }

Loading…
Cancel
Save