0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-cluster-worker-isconnected.js
Rich Trott 02fe8215f0 test: load common.js to test for global leaks
common.js contains code that checks for variables leaking into the
global namespace. Load common.js in all tests that do not
intentionally leak variables.

PR-URL: https://github.com/nodejs/node/pull/3095
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-10-01 20:16:35 -07:00

40 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
var cluster = require('cluster');
var assert = require('assert');
var util = require('util');
if (cluster.isMaster) {
var worker = cluster.fork();
assert.ok(worker.isConnected(),
'isConnected() should return true as soon as the worker has ' +
'been created.');
worker.on('disconnect', function() {
assert.ok(!worker.isConnected(),
'After a disconnect event has been emitted, ' +
'isConncted should return 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.');
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');
});
process.send('readyToDisconnect');
}