node/test/parallel/test-net-reuseport.js
theanarkh 7bc3e16da1
net: add UV_TCP_REUSEPORT for tcp
PR-URL: https://github.com/nodejs/node/pull/55408
Refs: https://github.com/libuv/libuv/pull/4407
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-10-21 13:10:53 +00:00

27 lines
741 B
JavaScript

'use strict';
const common = require('../common');
const { checkSupportReusePort, options } = require('../common/net');
const net = require('net');
function test(host) {
const server1 = net.createServer();
const server2 = net.createServer();
server1.listen({ ...options, host }, common.mustCall(() => {
const port = server1.address().port;
server2.listen({ ...options, host, port }, common.mustCall(() => {
server1.close();
server2.close();
}));
}));
server1.on('error', common.mustNotCall());
server2.on('error', common.mustNotCall());
}
checkSupportReusePort()
.then(() => {
test('127.0.0.1');
common.hasIPv6 && test('::');
}, () => {
common.skip('The `reusePort` option is not supported');
});