Skip to content

Commit 2e28783

Browse files
TrottMylesBorins
authored andcommitted
test: replace countdown with Promise.all() in cluster-net-listen tests
PR-URL: #32381 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent bdcc11f commit 2e28783

2 files changed

Lines changed: 42 additions & 39 deletions

File tree

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (!common.hasIPv6)
77
constassert=require('assert');
88
constcluster=require('cluster');
99
constnet=require('net');
10-
constCountdown=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
constworkers=[];
2019

21-
constcountdown=newCountdown(WORKER_ACCOUNT,()=>{
20+
for(leti=0;i<WORKER_ACCOUNT;i+=1){
21+
constmyWorker=newPromise((resolve)=>{
22+
constworker=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(leti=0;i<WORKER_ACCOUNT;i+=1){
40-
constworker=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,

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ if (!common.hasIPv6)
77
constassert=require('assert');
88
constcluster=require('cluster');
99
constnet=require('net');
10-
constCountdown=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
constworkers=[];
2019
letaddress;
2120

22-
constcountdown=newCountdown(WORKER_ACCOUNT,()=>{
23-
// Make sure the `ipv6Only` option works.
21+
for(leti=0;i<WORKER_ACCOUNT;i+=1){
22+
constmyWorker=newPromise((resolve)=>{
23+
constworker=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
constserver=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(leti=0;i<WORKER_ACCOUNT;i+=1){
37-
constworker=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)