1'use strict';
2const common = require('../common');
3const cluster = require('cluster');
4const net = require('net');
5
6if (cluster.isPrimary) {
7  cluster.schedulingPolicy = cluster.SCHED_RR;
8  cluster.fork();
9} else {
10  const server = net.createServer(common.mustNotCall());
11  server.listen(0, common.mustCall(() => {
12    net.connect(server.address().port);
13  }));
14  process.prependListener('internalMessage', common.mustCallAtLeast((message, handle) => {
15    if (message.act !== 'newconn') {
16      return;
17    }
18    // Make the worker drops the connection, see `rr` and `onconnection` in child.js
19    server.close();
20    const close = handle.close;
21    handle.close = common.mustCall(() => {
22      close.call(handle, common.mustCall(() => {
23        process.exit();
24      }));
25    });
26  }));
27}
28