2 * The goal of this test is to cover the Workers' implementation of
3 * Worker.prototype.destroy. Worker.prototype.destroy is called within
4 * the worker's context: once when the worker is still connected to the
5 * master, and another time when it's not connected to it, so that we cover
10 var cluster = require('cluster');
11 var assert = require('assert');
13 var worker1, worker2, workerExited, workerDisconnected;
15 if (cluster.isMaster) {
16 worker1 = cluster.fork();
17 worker2 = cluster.fork();
20 workerDisconnected = 0;
22 [worker1, worker2].forEach(function(worker) {
23 worker.on('disconnect', ondisconnect);
24 worker.on('exit', onexit);
27 process.on('exit', onProcessExit);
30 if (cluster.worker.id === 1) {
31 // Call destroy when worker is disconnected
32 cluster.worker.process.on('disconnect', function() {
33 cluster.worker.destroy();
36 cluster.worker.disconnect();
38 // Call destroy when worker is not disconnected yet
39 cluster.worker.destroy();
43 function onProcessExit() {
44 assert.equal(workerExited,
46 'When master exits, all workers should have exited too');
47 assert.equal(workerDisconnected,
49 'When master exits, all workers should have disconnected');
52 function ondisconnect() {