node/test/parallel/test-net-listen-handle-in-cluster-2.js
theanarkh 20525f14b9
lib: fix listen with handle in cluster worker
PR-URL: https://github.com/nodejs/node/pull/52056
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-03-14 14:54:31 +00:00

22 lines
704 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const cluster = require('cluster');
const { internalBinding } = require('internal/test/binding');
const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap');
// Test if the worker can listen with handle successfully
if (cluster.isPrimary) {
cluster.fork();
} else {
const handle = new TCP(TCPConstants.SOCKET);
const errno = handle.bind('0.0.0.0', 0);
assert.strictEqual(errno, 0);
// Execute _listen2 instead of cluster._getServer in listenInCluster
net.createServer().listen(handle, common.mustCall(() => {
process.exit(0);
}));
}