2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-09-28 00:31:36 +02:00
|
|
|
require('../common');
|
2014-08-16 02:20:32 +02:00
|
|
|
var cluster = require('cluster');
|
|
|
|
var assert = require('assert');
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
if (cluster.isMaster) {
|
|
|
|
var worker = cluster.fork();
|
|
|
|
|
|
|
|
assert.ok(worker.isConnected(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'isConnected() should return true as soon as the worker has ' +
|
|
|
|
'been created.');
|
2014-08-16 02:20:32 +02:00
|
|
|
|
|
|
|
worker.on('disconnect', function() {
|
|
|
|
assert.ok(!worker.isConnected(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'After a disconnect event has been emitted, ' +
|
|
|
|
'isConncted should return false');
|
2014-08-16 02:20:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
worker.on('message', function(msg) {
|
|
|
|
if (msg === 'readyToDisconnect') {
|
|
|
|
worker.disconnect();
|
|
|
|
}
|
2015-05-19 13:00:06 +02:00
|
|
|
});
|
2014-08-16 02:20:32 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
assert.ok(cluster.worker.isConnected(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'isConnected() should return true from within a worker at all ' +
|
|
|
|
'times.');
|
2014-08-16 02:20:32 +02:00
|
|
|
|
|
|
|
cluster.worker.process.on('disconnect', function() {
|
|
|
|
assert.ok(!cluster.worker.isConnected(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'isConnected() should return false from within a worker ' +
|
|
|
|
'after its underlying process has been disconnected from ' +
|
|
|
|
'the master');
|
|
|
|
});
|
2014-08-16 02:20:32 +02:00
|
|
|
|
|
|
|
process.send('readyToDisconnect');
|
|
|
|
}
|