• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const cluster = require('cluster');
5
6cluster.schedulingPolicy = cluster.SCHED_RR;
7
8if (cluster.isMaster) {
9  const worker1 = cluster.fork();
10  worker1.on('listening', common.mustCall(() => {
11    const worker2 = cluster.fork();
12    worker2.on('exit', (code, signal) => {
13      assert.strictEqual(
14        code,
15        0,
16        `worker${worker2.id} did not exit normally. Exit with code: ${code}`
17      );
18      assert.strictEqual(
19        signal,
20        null,
21        `worker${worker2.id} did not exit normally. Exit with signal: ${signal}`
22      );
23      worker1.disconnect();
24    });
25  }));
26
27  worker1.on('exit', common.mustCall((code, signal) => {
28    assert.strictEqual(
29      code,
30      0,
31      `worker${worker1.id} did not exit normally. Exit with code: ${code}`
32    );
33    assert.strictEqual(
34      signal,
35      null,
36      `worker${worker1.id} did not exit normally. Exit with code: ${signal}`
37    );
38  }));
39} else {
40  const net = require('net');
41  const server = net.createServer();
42  server.listen(0, common.mustCall(() => {
43    if (cluster.worker.id === 2) {
44      server.close(() => {
45        server.listen(0, common.mustCall(() => {
46          server.close(() => {
47            process.disconnect();
48          });
49        }));
50      });
51    }
52  }));
53}
54