mirror of
https://github.com/nodejs/node.git
synced 2024-11-28 22:46:31 +01:00
0e19476595
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: https://github.com/iojs/io.js/pull/172 Fix: iojs/io.js#139
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
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');
|
|
}
|