0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/parallel/test-cluster-worker-isdead.js
Stefania Sharp b07aa9264e
test: expand error message
PR-URL: https://github.com/nodejs/node/pull/15991
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-19 02:25:38 -02:00

33 lines
958 B
JavaScript

'use strict';
require('../common');
const cluster = require('cluster');
const assert = require('assert');
if (cluster.isMaster) {
const worker = cluster.fork();
let workerDead = worker.isDead();
assert.ok(!workerDead,
`isDead() returned ${workerDead}. isDead() should return ` +
'false right after the worker has been created.');
worker.on('exit', function() {
workerDead = worker.isDead();
assert.ok(workerDead,
`isDead() returned ${workerDead}. After an event has been ` +
'emitted, isDead should return true');
});
worker.on('message', function(msg) {
if (msg === 'readyToDie') {
worker.kill();
}
});
} else if (cluster.isWorker) {
const workerDead = cluster.worker.isDead();
assert.ok(!workerDead,
`isDead() returned ${workerDead}. isDead() should return ` +
'false when called from within a worker');
process.send('readyToDie');
}