src: don't error at startup when cwd doesn't exist
[platform/upstream/nodejs.git] / test / parallel / test-cluster-worker-destroy.js
1 /*
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
6  * both code paths.
7  */
8
9 require('../common');
10 var cluster = require('cluster');
11 var assert = require('assert');
12
13 var worker1, worker2, workerExited, workerDisconnected;
14
15 if (cluster.isMaster) {
16   worker1 = cluster.fork();
17   worker2 = cluster.fork();
18
19   workerExited = 0;
20   workerDisconnected = 0;
21
22   [worker1, worker2].forEach(function(worker) {
23     worker.on('disconnect', ondisconnect);
24     worker.on('exit', onexit);
25   });
26
27   process.on('exit', onProcessExit);
28
29 } else {
30   if (cluster.worker.id === 1) {
31     // Call destroy when worker is disconnected
32     cluster.worker.process.on('disconnect', function() {
33       cluster.worker.destroy();
34     });
35
36     cluster.worker.disconnect();
37   } else {
38     // Call destroy when worker is not disconnected yet
39     cluster.worker.destroy();
40   }
41 }
42
43 function onProcessExit() {
44   assert.equal(workerExited,
45                2,
46                'When master exits, all workers should have exited too');
47   assert.equal(workerDisconnected,
48                2,
49                'When master exits, all workers should have disconnected');
50 }
51
52 function ondisconnect() {
53   ++workerDisconnected;
54 }
55
56 function onexit() {
57   ++workerExited;
58 }