Skip to content

Commit 75c691b

Browse files
BamiehMylesBorins
authored andcommitted
test: wrap countdown callback in common.mustCall
This adds a implicit common.mustCall to the callback provided to the countdown. PR-URL: #18506 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 16aeddd commit 75c691b

15 files changed

+55
-29
lines changed

‎test/common/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Synchronous version of `spawnPwd`.
385385
The `Countdown` module provides a simple countdown mechanism for tests that
386386
require a particular action to be taken after a given number of completed
387387
tasks (for instance, shutting down an HTTP server after a specific number of
388-
requests).
388+
requests). The Countdown will fail the test if the remainder did not reach 0.
389389

390390
<!-- eslint-disable strict, required-modules -->
391391
```js

‎test/common/countdown.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
constassert=require('assert');
55
constkLimit=Symbol('limit');
66
constkCallback=Symbol('callback');
7+
constcommon=require('./');
78

89
classCountdown{
910
constructor(limit,cb){
1011
assert.strictEqual(typeoflimit,'number');
1112
assert.strictEqual(typeofcb,'function');
1213
this[kLimit]=limit;
13-
this[kCallback]=cb;
14+
this[kCallback]=common.mustCall(cb);
1415
}
1516

1617
dec(){

‎test/fixtures/failcounter.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
constCountdown=require('../common/countdown');
2+
newCountdown(2,()=>{});

‎test/parallel/test-common-countdown.js‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
constcommon=require('../common');
44
constassert=require('assert');
55
constCountdown=require('../common/countdown');
6+
constfixtures=require('../common/fixtures');
7+
const{ execFile }=require('child_process');
68

79
letdone='';
8-
9-
constcountdown=newCountdown(2,common.mustCall(()=>done=true));
10+
constcountdown=newCountdown(2,()=>done=true);
1011
assert.strictEqual(countdown.remaining,2);
1112
countdown.dec();
1213
assert.strictEqual(countdown.remaining,1);
1314
countdown.dec();
1415
assert.strictEqual(countdown.remaining,0);
1516
assert.strictEqual(done,true);
17+
18+
constfailFixtures=[
19+
[
20+
fixtures.path('failcounter.js'),
21+
'Mismatched <anonymous> function calls. Expected exactly 1, actual 0.',
22+
]
23+
];
24+
25+
for(constpoffailFixtures){
26+
const[file,expected]=p;
27+
execFile(process.argv[0],[file],common.mustCall((ex,stdout,stderr)=>{
28+
assert.ok(ex);
29+
assert.strictEqual(stderr,'');
30+
constfirstLine=stdout.split('\n').shift();
31+
assert.strictEqual(firstLine,expected);
32+
}));
33+
}

‎test/parallel/test-http-after-connect.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const server = http.createServer(common.mustCall((req, res) =>{
3232
setTimeout(()=>res.end(req.url),50);
3333
},2));
3434

35-
constcountdown=newCountdown(2,common.mustCall(()=>server.close()));
35+
constcountdown=newCountdown(2,()=>server.close());
3636

3737
server.on('connect',common.mustCall((req,socket)=>{
3838
socket.write('HTTP/1.1 200 Connection established\r\n\r\n');

‎test/parallel/test-http-agent-destroyed-socket.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const server = http.createServer(common.mustCall((req, res) =>{
8080
assert(request1.socket.destroyed);
8181
// assert not reusing the same socket, since it was destroyed.
8282
assert.notStrictEqual(request1.socket,request2.socket);
83-
constcountdown=newCountdown(2,common.mustCall(()=>server.close()));
83+
constcountdown=newCountdown(2,()=>server.close());
8484
request2.socket.on('close',common.mustCall(()=>countdown.dec()));
8585
response.on('end',common.mustCall(()=>countdown.dec()));
8686
response.resume();

‎test/parallel/test-http-agent-maxsockets-regress-4050.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const server = http.createServer(common.mustCall((req, res) =>{
1717
res.end('hello world');
1818
},6));
1919

20-
constcountdown=newCountdown(6,common.mustCall(()=>server.close()));
20+
constcountdown=newCountdown(6,()=>server.close());
2121

2222
functionget(path,callback){
2323
returnhttp.get({

‎test/parallel/test-http-agent-maxsockets.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function get(path, callback){
2626
},callback);
2727
}
2828

29-
constcountdown=newCountdown(2,common.mustCall(()=>{
29+
constcountdown=newCountdown(2,()=>{
3030
constfreepool=agent.freeSockets[Object.keys(agent.freeSockets)[0]];
3131
assert.strictEqual(freepool.length,2,
3232
`expect keep 2 free sockets, but got ${freepool.length}`);
3333
agent.destroy();
3434
server.close();
35-
}));
35+
});
3636

3737
functiondec(){
3838
process.nextTick(()=>countdown.dec());

‎test/parallel/test-http-client-abort.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Countdown = require('../common/countdown');
2626

2727
constN=8;
2828

29-
constcountdown=newCountdown(N,common.mustCall(()=>server.close()));
29+
constcountdown=newCountdown(N,()=>server.close());
3030

3131
constserver=http.Server(common.mustCall((req,res)=>{
3232
res.writeHead(200);
@@ -37,9 +37,9 @@ const server = http.Server(common.mustCall((req, res) =>{
3737
server.listen(0,common.mustCall(()=>{
3838

3939
constrequests=[];
40-
constreqCountdown=newCountdown(N,common.mustCall(()=>{
40+
constreqCountdown=newCountdown(N,()=>{
4141
requests.forEach((req)=>req.abort());
42-
}));
42+
});
4343

4444
constoptions={port: server.address().port};
4545

‎test/parallel/test-http-client-parse-error.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const http = require('http');
2525
constnet=require('net');
2626
constCountdown=require('../common/countdown');
2727

28-
constcountdown=newCountdown(2,common.mustCall(()=>server.close()));
28+
constcountdown=newCountdown(2,()=>server.close());
2929

3030
constpayloads=[
3131
'HTTP/1.1 302 Object Moved\r\nContent-Length: 0\r\n\r\nhi world',

0 commit comments

Comments
(0)