Skip to content

Commit

Permalink
test: use Promise.all() in test-cluster-net-listen-ipv6only-false
Browse files Browse the repository at this point in the history
Use Promise.all() instead of countdown in
test-cluster-net-listen-ipv6only-false.

Signed-off-by: Rich Trott <[email protected]>

PR-URL: #32398
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
Trott authored and addaleax committed Mar 30, 2020
1 parent 11d7cf1 commit b1e6f29
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions test/parallel/test-cluster-net-listen-ipv6only-false.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (!common.hasIPv6)
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
const Countdown = require('../common/countdown');

// This test ensures that dual-stack support still works for cluster module
// when `ipv6Only` is not `true`.
Expand All @@ -18,35 +17,37 @@ if (cluster.isMaster) {
const workers = [];
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({
port: address.port,
host: '0.0.0.0',
}, common.mustCall(() => {
socket.destroy();
workers.forEach((worker) => {
worker.disconnect();
resolvedWorkers.forEach((resolvedWorker) => {
resolvedWorker.disconnect();
});
}));
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 {
net.createServer().listen({
host,
Expand Down

0 comments on commit b1e6f29

Please sign in to comment.