mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 18:29:06 +00:00

Check if the worker 'isDead' instead of 'isConnected' as the 'disconnect' event is not guaranteed to be received before the 'exit' event. Remove the 'net' dependency as it is not used. PR-URL: https://github.com/nodejs/node/pull/3954 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
29 lines
743 B
JavaScript
29 lines
743 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var cluster = require('cluster');
|
|
var assert = require('assert');
|
|
|
|
if (cluster.isMaster) {
|
|
var worker = cluster.fork();
|
|
assert.ok(!worker.isDead(),
|
|
'isDead() should return false right after the worker has been ' +
|
|
'created.');
|
|
|
|
worker.on('exit', function() {
|
|
assert.ok(worker.isDead(),
|
|
'After an event has been emitted, ' +
|
|
'isDead should return true');
|
|
});
|
|
|
|
worker.on('message', function(msg) {
|
|
if (msg === 'readyToDie') {
|
|
worker.kill();
|
|
}
|
|
});
|
|
|
|
} else if (cluster.isWorker) {
|
|
assert.ok(!cluster.worker.isDead(),
|
|
'isDead() should return false when called from within a worker');
|
|
process.send('readyToDie');
|
|
}
|