test: fix flaky test-cluster-net-listen-ipv6only-none
test-cluster-net-listen-ipv6only-none was using port `0` for an IPv6-only operation and assuming that the operating system would supply a port that was also available in IPv4. However, CI results seem to indicate that a port can be supplied that is in use by IPv4 but available to IPv6, resulting in the test failing. Use `common.PORT` to avoid this issue. Fixes: https://github.com/nodejs/node/issues/29679 PR-URL: https://github.com/nodejs/node/pull/29681 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit is contained in:
parent
2487f39030
commit
1c5a3f0d09
@ -17,13 +17,16 @@ const WORKER_ACCOUNT = 3;
|
|||||||
|
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
const workers = new Map();
|
const workers = new Map();
|
||||||
let address;
|
|
||||||
|
|
||||||
const countdown = new Countdown(WORKER_ACCOUNT, () => {
|
const countdown = new Countdown(WORKER_ACCOUNT, () => {
|
||||||
// Make sure the `ipv6Only` option works.
|
// Make sure the `ipv6Only` option works. This is the part of the test that
|
||||||
|
// requires the whole test to use `common.PORT` rather than port `0`. If it
|
||||||
|
// used port `0` instead, then the operating system can supply a port that
|
||||||
|
// is available for the IPv6 interface but in use by the IPv4 interface.
|
||||||
|
// Refs: https://github.com/nodejs/node/issues/29679
|
||||||
const server = net.createServer().listen({
|
const server = net.createServer().listen({
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: address.port,
|
port: common.PORT,
|
||||||
}, common.mustCall(() => {
|
}, common.mustCall(() => {
|
||||||
// Exit.
|
// Exit.
|
||||||
server.close();
|
server.close();
|
||||||
@ -37,13 +40,9 @@ if (cluster.isMaster) {
|
|||||||
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
|
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
|
||||||
assert.strictEqual(statusCode, 0);
|
assert.strictEqual(statusCode, 0);
|
||||||
})).on('listening', common.mustCall((workerAddress) => {
|
})).on('listening', common.mustCall((workerAddress) => {
|
||||||
if (!address) {
|
assert.strictEqual(workerAddress.addressType, 6);
|
||||||
address = workerAddress;
|
assert.strictEqual(workerAddress.address, host);
|
||||||
} else {
|
assert.strictEqual(workerAddress.port, common.PORT);
|
||||||
assert.strictEqual(address.addressType, workerAddress.addressType);
|
|
||||||
assert.strictEqual(address.host, workerAddress.host);
|
|
||||||
assert.strictEqual(address.port, workerAddress.port);
|
|
||||||
}
|
|
||||||
countdown.dec();
|
countdown.dec();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ if (cluster.isMaster) {
|
|||||||
} else {
|
} else {
|
||||||
net.createServer().listen({
|
net.createServer().listen({
|
||||||
host,
|
host,
|
||||||
port: 0,
|
port: common.PORT,
|
||||||
ipv6Only: true,
|
ipv6Only: true,
|
||||||
}, common.mustCall());
|
}, common.mustCall());
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user