test: use Promise.all() in test-cluster-net-listen-ipv6only-false
Use Promise.all() instead of countdown in test-cluster-net-listen-ipv6only-false. Signed-off-by: Rich Trott <rtrott@gmail.com> PR-URL: https://github.com/nodejs/node/pull/32398 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
a1686e00ab
commit
2565442ac0
@ -7,7 +7,6 @@ if (!common.hasIPv6)
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const Countdown = require('../common/countdown');
|
|
||||||
|
|
||||||
// This test ensures that dual-stack support still works for cluster module
|
// This test ensures that dual-stack support still works for cluster module
|
||||||
// when `ipv6Only` is not `true`.
|
// when `ipv6Only` is not `true`.
|
||||||
@ -18,35 +17,37 @@ if (cluster.isMaster) {
|
|||||||
const workers = [];
|
const workers = [];
|
||||||
let address;
|
let address;
|
||||||
|
|
||||||
const countdown = new Countdown(WORKER_COUNT, () => {
|
for (let i = 0; i < WORKER_COUNT; i += 1) {
|
||||||
|
const myWorker = new Promise((resolve) => {
|
||||||
|
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
|
||||||
|
assert.strictEqual(statusCode, 0);
|
||||||
|
})).on('listening', common.mustCall((workerAddress) => {
|
||||||
|
if (!address) {
|
||||||
|
address = workerAddress;
|
||||||
|
} else {
|
||||||
|
assert.strictEqual(address.addressType, workerAddress.addressType);
|
||||||
|
assert.strictEqual(address.host, workerAddress.host);
|
||||||
|
assert.strictEqual(address.port, workerAddress.port);
|
||||||
|
}
|
||||||
|
resolve(worker);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
workers.push(myWorker);
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all(workers).then(common.mustCall((resolvedWorkers) => {
|
||||||
const socket = net.connect({
|
const socket = net.connect({
|
||||||
port: address.port,
|
port: address.port,
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
}, common.mustCall(() => {
|
}, common.mustCall(() => {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
workers.forEach((worker) => {
|
resolvedWorkers.forEach((resolvedWorker) => {
|
||||||
worker.disconnect();
|
resolvedWorker.disconnect();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
socket.on('error', common.mustNotCall());
|
socket.on('error', common.mustNotCall());
|
||||||
});
|
}));
|
||||||
|
|
||||||
for (let i = 0; i < WORKER_COUNT; i += 1) {
|
|
||||||
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
|
|
||||||
assert.strictEqual(statusCode, 0);
|
|
||||||
})).on('listening', common.mustCall((workerAddress) => {
|
|
||||||
if (!address) {
|
|
||||||
address = workerAddress;
|
|
||||||
} else {
|
|
||||||
assert.strictEqual(address.addressType, workerAddress.addressType);
|
|
||||||
assert.strictEqual(address.host, workerAddress.host);
|
|
||||||
assert.strictEqual(address.port, workerAddress.port);
|
|
||||||
}
|
|
||||||
countdown.dec();
|
|
||||||
}));
|
|
||||||
|
|
||||||
workers[i] = worker;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
net.createServer().listen({
|
net.createServer().listen({
|
||||||
host,
|
host,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user