Skip to content

Commit 79d48f9

Browse files
aduh95RafaelGSS
authored andcommitted
test: ensure assertions are reached on more tests
PR-URL: #60759 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 585e200 commit 79d48f9

57 files changed

Lines changed: 246 additions & 286 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎test/eslint.config_partial.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ export default [
194194
].join(',')}}/**/*.{js,mjs,cjs}`,
195195
`test/parallel/test-{${
196196
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
197-
Array.from({length: 7},(_,i)=>String.fromCharCode(0x61+i,42)).join(',')
198-
},http-*,http2-*,${
197+
Array.from({length: 13},(_,i)=>String.fromCharCode(0x61+i,42)).join(',')
198+
},${
199199
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
200200
Array.from({length: 5},(_,i)=>String.fromCharCode(0x61+25-i,42)).join(',')
201201
}}.{js,mjs,cjs}`,

‎test/parallel/test-h2leak-destroy-session-on-socket-ended.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ function client() {
6969
rejectUnauthorized: false,
7070
ALPNProtocols: ['h2']
7171
},()=>{
72-
client.end(Buffer.concat(h2fstStream.map((s)=>Buffer.from(s,'base64'))),(err)=>{
73-
assert.ifError(err);
74-
});
72+
client.end(Buffer.concat(h2fstStream.map((s)=>Buffer.from(s,'base64'))),common.mustSucceed());
7573
});
7674

7775
client.on('error',(error)=>{

‎test/parallel/test-handle-wrap-hasref.js‎

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
'use strict';
33

44
constcommon=require('../common');
5-
conststrictEqual=require('assert').strictEqual;
5+
constassert=require('assert');
66
const{ internalBinding }=require('internal/test/binding');
77

88
// child_process
99
{
1010
constspawn=require('child_process').spawn;
1111
constcmd=common.isWindows ? 'rundll32' : 'ls';
1212
constcp=spawn(cmd);
13-
strictEqual(cp._handle.hasRef(),
14-
true,'process_wrap: not initially refed');
13+
assert.strictEqual(cp._handle.hasRef(),true);
1514
cp.unref();
16-
strictEqual(cp._handle.hasRef(),
17-
false,'process_wrap: unref() ineffective');
15+
assert.strictEqual(cp._handle.hasRef(),false);
1816
cp.ref();
19-
strictEqual(cp._handle.hasRef(),
20-
true,'process_wrap: ref() ineffective');
17+
assert.strictEqual(cp._handle.hasRef(),true);
2118
cp._handle.close(common.mustCall(()=>
22-
strictEqual(cp._handle.hasRef(),
23-
false,'process_wrap: not unrefed on close')));
19+
assert.strictEqual(cp._handle.hasRef(),false)));
2420
}
2521

2622

@@ -32,17 +28,13 @@ const { kStateSymbol } = require('internal/dgram');
3228
constsock4=dgram.createSocket('udp4');
3329
consthandle=sock4[kStateSymbol].handle;
3430

35-
strictEqual(handle.hasRef(),
36-
true,'udp_wrap: ipv4: not initially refed');
31+
assert.strictEqual(handle.hasRef(),true);
3732
sock4.unref();
38-
strictEqual(handle.hasRef(),
39-
false,'udp_wrap: ipv4: unref() ineffective');
33+
assert.strictEqual(handle.hasRef(),false);
4034
sock4.ref();
41-
strictEqual(handle.hasRef(),
42-
true,'udp_wrap: ipv4: ref() ineffective');
35+
assert.strictEqual(handle.hasRef(),true);
4336
handle.close(common.mustCall(()=>
44-
strictEqual(handle.hasRef(),
45-
false,'udp_wrap: ipv4: not unrefed on close')));
37+
assert.strictEqual(handle.hasRef(),false)));
4638
}
4739

4840

@@ -51,85 +43,70 @@ const { kStateSymbol } = require('internal/dgram');
5143
constsock6=dgram.createSocket('udp6');
5244
consthandle=sock6[kStateSymbol].handle;
5345

54-
strictEqual(handle.hasRef(),
55-
true,'udp_wrap: ipv6: not initially refed');
46+
assert.strictEqual(handle.hasRef(),true);
5647
sock6.unref();
57-
strictEqual(handle.hasRef(),
58-
false,'udp_wrap: ipv6: unref() ineffective');
48+
assert.strictEqual(handle.hasRef(),false);
5949
sock6.ref();
60-
strictEqual(handle.hasRef(),
61-
true,'udp_wrap: ipv6: ref() ineffective');
50+
assert.strictEqual(handle.hasRef(),true);
6251
handle.close(common.mustCall(()=>
63-
strictEqual(handle.hasRef(),
64-
false,'udp_wrap: ipv6: not unrefed on close')));
52+
assert.strictEqual(handle.hasRef(),false)));
6553
}
6654

6755

6856
// pipe
6957
{
7058
const{ Pipe,constants: PipeConstants}=internalBinding('pipe_wrap');
7159
consthandle=newPipe(PipeConstants.SOCKET);
72-
strictEqual(handle.hasRef(),
73-
true,'pipe_wrap: not initially refed');
60+
assert.strictEqual(handle.hasRef(),true);
7461
handle.unref();
75-
strictEqual(handle.hasRef(),
76-
false,'pipe_wrap: unref() ineffective');
62+
assert.strictEqual(handle.hasRef(),false);
7763
handle.ref();
78-
strictEqual(handle.hasRef(),
79-
true,'pipe_wrap: ref() ineffective');
64+
assert.strictEqual(handle.hasRef(),true);
8065
handle.close(common.mustCall(()=>
81-
strictEqual(handle.hasRef(),
82-
false,'pipe_wrap: not unrefed on close')));
66+
assert.strictEqual(handle.hasRef(),false)));
8367
}
8468

8569

8670
// tcp
8771
{
8872
constnet=require('net');
8973
constserver=net.createServer(()=>{}).listen(0);
90-
strictEqual(server._handle.hasRef(),
91-
true,'tcp_wrap: not initially refed');
92-
strictEqual(server._unref,
93-
false,'tcp_wrap: _unref initially incorrect');
74+
assert.strictEqual(server._handle.hasRef(),true);
75+
assert.strictEqual(server._unref,false);
9476
server.unref();
95-
strictEqual(server._handle.hasRef(),
96-
false,'tcp_wrap: unref() ineffective');
97-
strictEqual(server._unref,
98-
true,'tcp_wrap: _unref not updated on unref()');
77+
assert.strictEqual(server._handle.hasRef(),false);
78+
assert.strictEqual(server._unref,true);
9979
server.ref();
100-
strictEqual(server._handle.hasRef(),
101-
true,'tcp_wrap: ref() ineffective');
102-
strictEqual(server._unref,
103-
false,'tcp_wrap: _unref not updated on ref()');
80+
assert.strictEqual(server._handle.hasRef(),true);
81+
assert.strictEqual(server._unref,false);
10482
server._handle.close(common.mustCall(()=>
105-
strictEqual(server._handle.hasRef(),
106-
false,'tcp_wrap: not unrefed on close')));
83+
assert.strictEqual(server._handle.hasRef(),false)));
10784
}
10885

10986
// timers
11087
{
111-
strictEqual(process.getActiveResourcesInfo().filter(
88+
assert.strictEqual(process.getActiveResourcesInfo().filter(
11289
(type)=>type==='Timeout').length,0);
11390
consttimeout=setTimeout(()=>{},500);
114-
strictEqual(process.getActiveResourcesInfo().filter(
91+
assert.strictEqual(process.getActiveResourcesInfo().filter(
11592
(type)=>type==='Timeout').length,1);
11693
timeout.unref();
117-
strictEqual(process.getActiveResourcesInfo().filter(
94+
assert.strictEqual(process.getActiveResourcesInfo().filter(
11895
(type)=>type==='Timeout').length,0);
11996
timeout.ref();
120-
strictEqual(process.getActiveResourcesInfo().filter(
97+
assert.strictEqual(process.getActiveResourcesInfo().filter(
12198
(type)=>type==='Timeout').length,1);
12299

123-
strictEqual(process.getActiveResourcesInfo().filter(
100+
assert.strictEqual(process.getActiveResourcesInfo().filter(
124101
(type)=>type==='Immediate').length,0);
125102
constimmediate=setImmediate(()=>{});
126-
strictEqual(process.getActiveResourcesInfo().filter(
103+
assert.strictEqual(process.getActiveResourcesInfo().filter(
127104
(type)=>type==='Immediate').length,1);
128105
immediate.unref();
129-
strictEqual(process.getActiveResourcesInfo().filter(
106+
assert.strictEqual(process.getActiveResourcesInfo().filter(
130107
(type)=>type==='Immediate').length,0);
131108
immediate.ref();
132-
strictEqual(process.getActiveResourcesInfo().filter(
109+
assert.strictEqual(process.getActiveResourcesInfo().filter(
133110
(type)=>type==='Immediate').length,1);
134111
}
135112

‎test/parallel/test-heapdump-async-hooks-init-promise.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ async_hooks.createHook({
3131
if(promiseIds.includes(id))createSnapshot();
3232
},
3333

34-
promiseResolve(id){
34+
promiseResolve: common.mustCallAtLeast((id)=>{
3535
assert(promiseIds.includes(id));
3636
createSnapshot();
37-
},
37+
}),
3838

3939
destroy(id){
4040
if(promiseIds.includes(id))createSnapshot();

‎test/parallel/test-http.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const server = http.Server(common.mustCall((req, res) => {
6161
},3));
6262
server.listen(0);
6363

64-
server.on('listening',()=>{
64+
server.on('listening',common.mustCall(()=>{
6565
constagent=newhttp.Agent({port: server.address().port,maxSockets: 1});
6666
constreq=http.get({
6767
port: server.address().port,
@@ -133,4 +133,4 @@ server.on('listening', () => {
133133
}));
134134
req.end();
135135
}),2);
136-
});
136+
}));

‎test/parallel/test-https-agent-create-connection.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const expectedHeader = /^HTTP\/1\.1 200 OK/;
1919
constexpectedBody=/helloworld\n/;
2020
constexpectCertError=/^UNABLE_TO_VERIFY_LEAF_SIGNATURE$/;
2121

22-
constcheckRequest=(socket,server)=>{
22+
functioncheckRequest(socket,server){
2323
letresult='';
2424
socket.on('connect',common.mustCall((data)=>{
2525
socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');

‎test/parallel/test-https-agent-keylog.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const server = https.createServer({
3636
});
3737
});
3838

39-
constverifyKeylog=(line,tlsSocket)=>{
39+
constverifyKeylog=common.mustCallAtLeast((line,tlsSocket)=>{
4040
assert(Buffer.isBuffer(line));
4141
assert.strictEqual(tlsSocket.encrypted,true);
42-
};
42+
});
4343
server.on('keylog',common.mustCall(verifyKeylog,10));
4444
https.globalAgent.on('keylog',common.mustCall(verifyKeylog,10));

‎test/parallel/test-https-agent-servername.js‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ const server = https.Server(options, (req, res) => {
2121
});
2222

2323

24-
server.listen(0,function(){
24+
server.listen(0,common.mustCall(function(){
2525
https.get({
2626
path: '/',
2727
port: this.address().port,
2828
rejectUnauthorized: true,
2929
servername: 'agent1',
3030
ca: options.ca
31-
},(res)=>{
31+
},common.mustCall((res)=>{
3232
res.resume();
3333
assert.strictEqual(res.statusCode,200);
3434
server.close();
35-
}).on('error',(e)=>{
36-
console.log(e.message);
37-
process.exit(1);
38-
});
39-
});
35+
})).on('error',common.mustNotCall());
36+
}));

‎test/parallel/test-https-agent-sni.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const server = https.Server(options, function(req, res) {
2727
res.end('hello world');
2828
});
2929

30-
server.listen(0,function(){
30+
server.listen(0,common.mustCall(function(){
3131
functionexpectResponse(id){
3232
returncommon.mustCall(function(res){
3333
res.resume();
@@ -59,4 +59,4 @@ server.listen(0, function() {
5959
servername: '',
6060
rejectUnauthorized: false
6161
},expectResponse(false));
62-
});
62+
}));

‎test/parallel/test-https-agent-unref-socket.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ if (process.argv[2] === 'localhost') {
1717
constnet=require('net');
1818
constserver=net.createServer();
1919
server.listen(0);
20-
server.on('listening',()=>{
20+
server.on('listening',common.mustCall(()=>{
2121
constport=server.address().port;
2222
const{ fork }=require('child_process');
2323
constchild=fork(__filename,['localhost',port],{});
24-
child.on('close',(exit_code)=>{
24+
child.on('close',common.mustCall((exit_code)=>{
2525
server.close();
2626
assert.strictEqual(exit_code,0);
27-
});
28-
});
27+
}));
28+
}));
2929
}

0 commit comments

Comments
 (0)