1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const cluster = require('cluster'); 5 6cluster.schedulingPolicy = cluster.SCHED_NONE; 7 8if (cluster.isPrimary) { 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(code, 0, 14 'worker2 did not exit normally. ' + 15 `exited with code ${code}`); 16 assert.strictEqual(signal, null, 17 'worker2 did not exit normally. ' + 18 `exited with signal ${signal}`); 19 worker1.disconnect(); 20 }); 21 })); 22 23 worker1.on('exit', common.mustCall((code, signal) => { 24 assert.strictEqual(code, 0, 25 'worker1 did not exit normally. ' + 26 `exited with code ${code}`); 27 assert.strictEqual(signal, null, 28 'worker1 did not exit normally. ' + 29 `exited with signal ${signal}`); 30 })); 31} else { 32 const net = require('net'); 33 const server = net.createServer(); 34 server.listen(0, common.mustCall(() => { 35 if (cluster.worker.id === 2) { 36 server.close(() => { 37 server.listen(0, common.mustCall(() => { 38 server.close(() => { 39 process.disconnect(); 40 }); 41 })); 42 }); 43 } 44 })); 45} 46