2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-09-27 15:31:36 -07:00
|
|
|
require('../common');
|
2014-08-15 17:20:32 -07:00
|
|
|
var cluster = require('cluster');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
if (cluster.isMaster) {
|
|
|
|
var worker = cluster.fork();
|
|
|
|
assert.ok(!worker.isDead(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'isDead() should return false right after the worker has been ' +
|
|
|
|
'created.');
|
2014-08-15 17:20:32 -07:00
|
|
|
|
|
|
|
worker.on('exit', function() {
|
2015-11-21 15:33:51 +01:00
|
|
|
assert.ok(worker.isDead(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'After an event has been emitted, ' +
|
|
|
|
'isDead should return true');
|
|
|
|
});
|
2014-08-15 17:20:32 -07:00
|
|
|
|
|
|
|
worker.on('message', function(msg) {
|
2015-05-19 13:00:06 +02:00
|
|
|
if (msg === 'readyToDie') {
|
|
|
|
worker.kill();
|
|
|
|
}
|
2014-08-15 17:20:32 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
} else if (cluster.isWorker) {
|
|
|
|
assert.ok(!cluster.worker.isDead(),
|
2015-05-19 13:00:06 +02:00
|
|
|
'isDead() should return false when called from within a worker');
|
2014-08-15 17:20:32 -07:00
|
|
|
process.send('readyToDie');
|
|
|
|
}
|