1 // In Node 4.2.1 on operating systems other than Linux, this test triggers an
2 // assertion in cluster.js. The assertion protects against memory leaks.
3 // https://github.com/nodejs/node/pull/3510
6 const common = require('../common');
7 const assert = require('assert');
8 const net = require('net');
9 const cluster = require('cluster');
10 cluster.schedulingPolicy = cluster.SCHED_NONE;
12 if (cluster.isMaster) {
13 var conn, worker1, worker2;
15 worker1 = cluster.fork();
16 worker1.on('message', common.mustCall(function() {
17 worker2 = cluster.fork();
18 worker2.on('online', function() {
19 conn = net.connect(common.PORT, common.mustCall(function() {
23 conn.on('error', function(e) {
25 if (e.code !== 'ECONNRESET')
31 cluster.on('exit', function(worker, exitCode, signalCode) {
32 assert(worker === worker1 || worker === worker2);
33 assert.strictEqual(exitCode, 0);
34 assert.strictEqual(signalCode, null);
35 if (Object.keys(cluster.workers).length === 0)
42 const server = net.createServer(function(c) {
43 c.on('error', function(e) {
44 // ECONNRESET is OK, so we don't exit with code !== 0
45 if (e.code !== 'ECONNRESET')
51 server.listen(common.PORT, function() {
52 process.send('listening');