• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const cluster = require('cluster');
4const assert = require('assert');
5
6if (cluster.isMaster) {
7  const worker = cluster.fork();
8  let workerDead = worker.isDead();
9  assert.ok(!workerDead,
10            `isDead() returned ${workerDead}. isDead() should return ` +
11            'false right after the worker has been created.');
12
13  worker.on('exit', function() {
14    workerDead = worker.isDead();
15    assert.ok(workerDead,
16              `isDead() returned ${workerDead}. After an event has been ` +
17              'emitted, isDead should return true');
18  });
19
20  worker.on('message', function(msg) {
21    if (msg === 'readyToDie') {
22      worker.kill();
23    }
24  });
25
26} else if (cluster.isWorker) {
27  const workerDead = cluster.worker.isDead();
28  assert.ok(!workerDead,
29            `isDead() returned ${workerDead}. isDead() should return ` +
30            'false when called from within a worker');
31  process.send('readyToDie');
32}
33