node/test/parallel/test-cluster-dgram-reuseport.js
Luigi Pinca 84fe809535
test: remove unneeded listeners
Unhandled `'error'` events will make the process exit with an unclean
exit code anyway.

PR-URL: https://github.com/nodejs/node/pull/55486
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
2024-10-29 21:52:09 +00:00

40 lines
1008 B
JavaScript

'use strict';
const common = require('../common');
if (common.isWindows)
common.skip('dgram clustering is currently not supported on windows.');
const { checkSupportReusePort, options } = require('../common/udp');
const assert = require('assert');
const cluster = require('cluster');
const dgram = require('dgram');
if (cluster.isPrimary) {
checkSupportReusePort().then(() => {
cluster.fork().on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
}, () => {
common.skip('The `reusePort` option is not supported');
});
return;
}
let waiting = 2;
function close() {
if (--waiting === 0)
cluster.worker.disconnect();
}
// Test if the worker requests the main process to create a socket
cluster._getServer = common.mustNotCall();
const socket1 = dgram.createSocket(options);
const socket2 = dgram.createSocket(options);
socket1.bind(0, () => {
socket2.bind(socket1.address().port, () => {
socket1.close(close);
socket2.close(close);
});
});