11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst cluster = require('cluster'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciif (cluster.isPrimary) { 71cb0ef41Sopenharmony_ci const worker = cluster.fork(); 81cb0ef41Sopenharmony_ci let workerDead = worker.isDead(); 91cb0ef41Sopenharmony_ci assert.ok(!workerDead, 101cb0ef41Sopenharmony_ci `isDead() returned ${workerDead}. isDead() should return ` + 111cb0ef41Sopenharmony_ci 'false right after the worker has been created.'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci worker.on('exit', function() { 141cb0ef41Sopenharmony_ci workerDead = worker.isDead(); 151cb0ef41Sopenharmony_ci assert.ok(workerDead, 161cb0ef41Sopenharmony_ci `isDead() returned ${workerDead}. After an event has been ` + 171cb0ef41Sopenharmony_ci 'emitted, isDead should return true'); 181cb0ef41Sopenharmony_ci }); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci worker.on('message', function(msg) { 211cb0ef41Sopenharmony_ci if (msg === 'readyToDie') { 221cb0ef41Sopenharmony_ci worker.kill(); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci} else if (cluster.isWorker) { 271cb0ef41Sopenharmony_ci const workerDead = cluster.worker.isDead(); 281cb0ef41Sopenharmony_ci assert.ok(!workerDead, 291cb0ef41Sopenharmony_ci `isDead() returned ${workerDead}. isDead() should return ` + 301cb0ef41Sopenharmony_ci 'false when called from within a worker'); 311cb0ef41Sopenharmony_ci process.send('readyToDie'); 321cb0ef41Sopenharmony_ci} 33