0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-cluster-shared-leak.js
Michael Dawson 15164cebce lib,src: update cluster to use Parent
Doc deprecate isMaster and setupMaster in favor
of isPrimary and setupPrimary.

Signed-off-by: Michael Dawson <mdawson@devrus.com>

PR-URL: https://github.com/nodejs/node/pull/36478
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
2021-01-05 15:41:45 -05:00

52 lines
1.4 KiB
JavaScript

// In Node 4.2.1 on operating systems other than Linux, this test triggers an
// assertion in cluster.js. The assertion protects against memory leaks.
// https://github.com/nodejs/node/pull/3510
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const cluster = require('cluster');
cluster.schedulingPolicy = cluster.SCHED_NONE;
if (cluster.isPrimary) {
let conn, worker2;
const worker1 = cluster.fork();
worker1.on('listening', common.mustCall(function(address) {
worker2 = cluster.fork();
worker2.on('online', function() {
conn = net.connect(address.port, common.mustCall(function() {
worker1.disconnect();
worker2.disconnect();
}));
conn.on('error', function(e) {
// ECONNRESET is OK
if (e.code !== 'ECONNRESET')
throw e;
});
});
}));
cluster.on('exit', function(worker, exitCode, signalCode) {
assert(worker === worker1 || worker === worker2);
assert.strictEqual(exitCode, 0);
assert.strictEqual(signalCode, null);
if (Object.keys(cluster.workers).length === 0)
conn.destroy();
});
return;
}
const server = net.createServer(function(c) {
c.on('error', function(e) {
// ECONNRESET is OK, so we don't exit with code !== 0
if (e.code !== 'ECONNRESET')
throw e;
});
c.end('bye');
});
server.listen(0);