Skip to content

Commit bfc81ca

Browse files
authored
test: ensure assertions are reachable in test/async-hooks
PR-URL: #60150 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 712cee9 commit bfc81ca

27 files changed

Lines changed: 142 additions & 168 deletions

‎test/async-hooks/hook-checks.js‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
constassert=require('assert');
44

55
/**
@@ -15,7 +15,7 @@ const assert = require('assert');
1515
* @param {string} stage the name of the stage in the test at which we are
1616
* checking the invocations
1717
*/
18-
exports.checkInvocations=functioncheckInvocations(activity,hooks,stage){
18+
exports.checkInvocations=common.mustCallAtLeast(functioncheckInvocations(activity,hooks,stage){
1919
conststageInfo=`Checking invocations at stage "${stage}":\n `;
2020

2121
assert.ok(activity!=null,
@@ -24,9 +24,7 @@ exports.checkInvocations = function checkInvocations(activity, hooks, stage) {
2424
);
2525

2626
// Check that actual invocations for all hooks match the expected invocations
27-
['init','before','after','destroy','promiseResolve'].forEach(checkHook);
28-
29-
functioncheckHook(k){
27+
['init','before','after','destroy','promiseResolve'].forEach((k)=>{
3028
constval=hooks[k];
3129
// Not expected ... all good
3230
if(val==null)return;
@@ -49,5 +47,5 @@ exports.checkInvocations = function checkInvocations(activity, hooks, stage) {
4947
`time(s), but expected ${val} invocation(s).`;
5048
assert.strictEqual(activity[k].length,val,msg2);
5149
}
52-
}
53-
};
50+
});
51+
},0);

‎test/async-hooks/test-async-exec-resource-http-32060.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
constassert=require('assert');
44
const{
55
executionAsyncResource,
@@ -22,16 +22,16 @@ const server = http.createServer((req, res) => {
2222
},1000);
2323
});
2424

25-
server.listen(0,()=>{
25+
server.listen(0,common.mustCallAtLeast(()=>{
2626
assert.strictEqual(executionAsyncResource(),hooked[executionAsyncId()]);
27-
http.get({port: server.address().port},(res)=>{
27+
http.get({port: server.address().port},common.mustCallAtLeast((res)=>{
2828
assert.strictEqual(executionAsyncResource(),hooked[executionAsyncId()]);
29-
res.on('data',()=>{
29+
res.on('data',common.mustCallAtLeast(()=>{
3030
assert.strictEqual(executionAsyncResource(),hooked[executionAsyncId()]);
31-
});
32-
res.on('end',()=>{
31+
}));
32+
res.on('end',common.mustCall(()=>{
3333
assert.strictEqual(executionAsyncResource(),hooked[executionAsyncId()]);
3434
server.close();
35-
});
36-
});
37-
});
35+
}));
36+
}));
37+
}));

‎test/async-hooks/test-async-exec-resource-http.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
constcommon=require('../common');
44
constassert=require('assert');
55
const{
66
executionAsyncResource,
@@ -20,11 +20,11 @@ const server = http.createServer((req, res) => {
2020
res.end('ok');
2121
});
2222

23-
server.listen(0,()=>{
23+
server.listen(0,common.mustCall(()=>{
2424
assert.strictEqual(executionAsyncResource(),hooked[executionAsyncId()]);
2525

26-
http.get({port: server.address().port},()=>{
26+
http.get({port: server.address().port},common.mustCall(()=>{
2727
assert.strictEqual(executionAsyncResource(),hooked[executionAsyncId()]);
2828
server.close();
29-
});
30-
});
29+
}));
30+
}));
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
constassert=require('assert');
44
const{ AsyncLocalStorage }=require('async_hooks');
55

66
constasyncLocalStorage=newAsyncLocalStorage();
77

8-
asyncLocalStorage.run({},(runArg)=>{
8+
asyncLocalStorage.run({},common.mustCall((runArg)=>{
99
assert.strictEqual(runArg,'foo');
10-
asyncLocalStorage.exit((exitArg)=>{
10+
asyncLocalStorage.exit(common.mustCall((exitArg)=>{
1111
assert.strictEqual(exitArg,'bar');
12-
},'bar');
13-
},'foo');
12+
}),'bar');
13+
}),'foo');
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
constcommon=require('../common');
44

55
// Regression tests for https://github.com/nodejs/node/issues/40693
66

@@ -10,17 +10,17 @@ const { AsyncLocalStorage } = require('async_hooks');
1010

1111
dgram.createSocket('udp4')
1212
.on('message',function(msg,rinfo){this.send(msg,rinfo.port);})
13-
.on('listening',function(){
13+
.on('listening',common.mustCall(function(){
1414
constasyncLocalStorage=newAsyncLocalStorage();
1515
conststore={val: 'abcd'};
16-
asyncLocalStorage.run(store,()=>{
16+
asyncLocalStorage.run(store,common.mustCall(()=>{
1717
constclient=dgram.createSocket('udp4');
18-
client.on('message',(msg,rinfo)=>{
18+
client.on('message',common.mustCall((msg,rinfo)=>{
1919
assert.deepStrictEqual(asyncLocalStorage.getStore(),store);
2020
client.close();
2121
this.close();
22-
});
22+
}));
2323
client.send('Hello, world!',this.address().port);
24-
});
25-
})
24+
}));
25+
}))
2626
.bind(0);
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
constassert=require('assert');
44
const{ AsyncLocalStorage }=require('async_hooks');
55

66
constasyncLocalStorage=newAsyncLocalStorage();
77

8-
asyncLocalStorage.run(newMap(),()=>{
8+
asyncLocalStorage.run(newMap(),common.mustCall(()=>{
99
asyncLocalStorage.getStore().set('foo','bar');
1010
process.nextTick(()=>{
1111
assert.strictEqual(asyncLocalStorage.getStore().get('foo'),'bar');
@@ -17,16 +17,16 @@ asyncLocalStorage.run(new Map(), () => {
1717
assert.strictEqual(asyncLocalStorage.getStore(),undefined);
1818

1919
// Calls to exit() should not mess with enabled status
20-
asyncLocalStorage.exit(()=>{
20+
asyncLocalStorage.exit(common.mustCall(()=>{
2121
assert.strictEqual(asyncLocalStorage.getStore(),undefined);
22-
});
22+
}));
2323
assert.strictEqual(asyncLocalStorage.getStore(),undefined);
2424

2525
process.nextTick(()=>{
2626
assert.strictEqual(asyncLocalStorage.getStore(),undefined);
27-
asyncLocalStorage.run(newMap().set('bar','foo'),()=>{
27+
asyncLocalStorage.run(newMap().set('bar','foo'),common.mustCall(()=>{
2828
assert.strictEqual(asyncLocalStorage.getStore().get('bar'),'foo');
29-
});
29+
}));
3030
});
3131
});
32-
});
32+
}));
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
'use strict';
2-
require('../common');
2+
constcommon=require('../common');
33
constassert=require('assert');
44
const{ AsyncLocalStorage }=require('async_hooks');
55

66
constasyncLocalStorage=newAsyncLocalStorage();
77

8-
setImmediate(()=>{
8+
setImmediate(common.mustCall(()=>{
99
conststore={foo: 'bar'};
1010
asyncLocalStorage.enterWith(store);
1111

1212
assert.strictEqual(asyncLocalStorage.getStore(),store);
13-
setTimeout(()=>{
13+
setTimeout(common.mustCall(()=>{
1414
assert.strictEqual(asyncLocalStorage.getStore(),store);
15-
},10);
16-
});
15+
}),10);
16+
}));
1717

18-
setTimeout(()=>{
18+
setTimeout(common.mustCall(()=>{
1919
assert.strictEqual(asyncLocalStorage.getStore(),undefined);
20-
},10);
20+
}),10);

‎test/async-hooks/test-async-local-storage-gcable.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const { onGC } = require('../common/gc');
1111

1212
letasyncLocalStorage=newAsyncLocalStorage();
1313

14-
asyncLocalStorage.run({},()=>{
14+
asyncLocalStorage.run({},common.mustCall(()=>{
1515
asyncLocalStorage.disable();
1616

1717
onGC(asyncLocalStorage,{ongc: common.mustCall()});
18-
});
18+
}));
1919

2020
if(AsyncContextFrame.enabled){
2121
// This disable() is needed to remove reference form AsyncContextFrame

‎test/async-hooks/test-async-local-storage-http-agent.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ server.listen(0, common.mustCall(() => {
2121
constport=server.address().port;
2222

2323
for(leti=0;i<N;i++){
24-
asyncLocalStorage.run(i,()=>{
24+
asyncLocalStorage.run(i,common.mustCall(()=>{
2525
http.get({ agent, port },common.mustCall((res)=>{
2626
assert.strictEqual(asyncLocalStorage.getStore(),i);
2727
if(++responses===N){
@@ -30,6 +30,6 @@ server.listen(0, common.mustCall(() => {
3030
}
3131
res.resume();
3232
}));
33-
});
33+
}));
3434
}
3535
}));

‎test/async-hooks/test-async-local-storage-http.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const{ mustCall }=require('../common');
33
constassert=require('assert');
44
const{ AsyncLocalStorage }=require('async_hooks');
55
consthttp=require('http');
@@ -13,9 +13,9 @@ server.listen(0, () => {
1313
asyncLocalStorage.run(newMap(),()=>{
1414
conststore=asyncLocalStorage.getStore();
1515
store.set('hello','world');
16-
http.get({host: 'localhost',port: server.address().port},()=>{
16+
http.get({host: 'localhost',port: server.address().port},mustCall(()=>{
1717
assert.strictEqual(asyncLocalStorage.getStore().get('hello'),'world');
1818
server.close();
19-
});
19+
}));
2020
});
2121
});

0 commit comments

Comments
 (0)