GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: replace countdown with Promise.all() in cluster-net-listen tests · nodejs/node@97e352d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/sequential
    • test-cluster-net-listen-ipv6only-none.js
    • test-cluster-net-listen-ipv6only-rr.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/sequential/test-cluster-net-listen-ipv6only-none.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-cluster-net-listen-ipv6only-none.js
+19-18Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (!common.hasIPv6)
77
const assert = require('assert');
88
const cluster = require('cluster');
99
const net = require('net');
10-
const Countdown = require('../common/countdown');
1110

1211
// This test ensures that the `ipv6Only` option in `net.Server.listen()`
1312
// works as expected when we use cluster with `SCHED_NONE` schedulingPolicy.
@@ -18,7 +17,22 @@ const WORKER_ACCOUNT = 3;
1817
if (cluster.isMaster) {
1918
const workers = [];
2019

21-
const countdown = new Countdown(WORKER_ACCOUNT, () => {
20+
for (let i = 0; i < WORKER_ACCOUNT; i += 1) {
21+
const myWorker = new Promise((resolve) => {
22+
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
23+
assert.strictEqual(statusCode, 0);
24+
})).on('listening', common.mustCall((workerAddress) => {
25+
assert.strictEqual(workerAddress.addressType, 6);
26+
assert.strictEqual(workerAddress.address, host);
27+
assert.strictEqual(workerAddress.port, common.PORT);
28+
resolve(worker);
29+
}));
30+
});
31+
32+
workers.push(myWorker);
33+
}
34+
35+
Promise.all(workers).then(common.mustCall((resolvedWorkers) => {
2236
// Make sure the `ipv6Only` option works. This is the part of the test that
2337
// requires the whole test to use `common.PORT` rather than port `0`. If it
2438
// used port `0` instead, then the operating system can supply a port that
@@ -30,24 +44,11 @@ if (cluster.isMaster) {
3044
}, common.mustCall(() => {
3145
// Exit.
3246
server.close();
33-
workers.forEach((worker) => {
34-
worker.disconnect();
47+
resolvedWorkers.forEach((resolvedWorker) => {
48+
resolvedWorker.disconnect();
3549
});
3650
}));
37-
});
38-
39-
for (let i = 0; i < WORKER_ACCOUNT; i += 1) {
40-
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
41-
assert.strictEqual(statusCode, 0);
42-
})).on('listening', common.mustCall((workerAddress) => {
43-
assert.strictEqual(workerAddress.addressType, 6);
44-
assert.strictEqual(workerAddress.address, host);
45-
assert.strictEqual(workerAddress.port, common.PORT);
46-
countdown.dec();
47-
}));
48-
49-
workers[i] = worker;
50-
}
51+
}));
5152
} else {
5253
net.createServer().listen({
5354
host,
Collapse file

‎test/sequential/test-cluster-net-listen-ipv6only-rr.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-cluster-net-listen-ipv6only-rr.js
+23-21Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (!common.hasIPv6)
77
const assert = require('assert');
88
const cluster = require('cluster');
99
const net = require('net');
10-
const Countdown = require('../common/countdown');
1110

1211
// This test ensures that the `ipv6Only` option in `net.Server.listen()`
1312
// works as expected when we use cluster with `SCHED_RR` schedulingPolicy.
@@ -19,34 +18,37 @@ if (cluster.isMaster) {
1918
const workers = [];
2019
let address;
2120

22-
const countdown = new Countdown(WORKER_ACCOUNT, () => {
23-
// Make sure the `ipv6Only` option works.
21+
for (let i = 0; i < WORKER_ACCOUNT; i += 1) {
22+
const myWorker = new Promise((resolve) => {
23+
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
24+
assert.strictEqual(statusCode, 0);
25+
})).on('listening', common.mustCall((workerAddress) => {
26+
if (!address) {
27+
address = workerAddress;
28+
} else {
29+
assert.deepStrictEqual(workerAddress, address);
30+
}
31+
resolve(worker);
32+
}));
33+
});
34+
35+
workers.push(myWorker);
36+
}
37+
38+
Promise.all(workers).then(common.mustCall((resolvedWorkers) => {
39+
// Make sure the `ipv6Only` option works. Should be able to use the port on
40+
// IPv4.
2441
const server = net.createServer().listen({
2542
host: '0.0.0.0',
2643
port: address.port,
2744
}, common.mustCall(() => {
2845
// Exit.
2946
server.close();
30-
workers.forEach((worker) => {
31-
worker.disconnect();
47+
resolvedWorkers.forEach((resolvedWorker) => {
48+
resolvedWorker.disconnect();
3249
});
3350
}));
34-
});
35-
36-
for (let i = 0; i < WORKER_ACCOUNT; i += 1) {
37-
const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
38-
assert.strictEqual(statusCode, 0);
39-
})).on('listening', common.mustCall((workerAddress) => {
40-
if (!address) {
41-
address = workerAddress;
42-
} else {
43-
assert.deepStrictEqual(workerAddress, address);
44-
}
45-
countdown.dec();
46-
}));
47-
48-
workers[i] = worker;
49-
}
51+
}));
5052
} else {
5153
// As the cluster member has the potential to grab any port
5254
// from the environment, this can cause collision when master

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.