Skip to content

Commit 674befe

Browse files
committed
test: ensure assertions are reachable in test/sequential
PR-URL: #60412 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 952c08a commit 674befe

33 files changed

+118
-139
lines changed

‎test/eslint.config_partial.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export default [
177177
'pummel',
178178
'report',
179179
'sea',
180+
'sequential',
180181
'sqlite',
181182
'system-ca',
182183
'test426',

‎test/sequential/test-child-process-execsync.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ const args = [
147147
assert.strictEqual(typeoferr.pid,'number');
148148
spawnSyncKeys
149149
.filter((key)=>key!=='pid')
150-
.forEach((key)=>{
150+
.forEach(common.mustCallAtLeast((key)=>{
151151
assert.deepStrictEqual(err[key],spawnSyncResult[key]);
152-
});
152+
}));
153153
returntrue;
154154
});
155155
}

‎test/sequential/test-child-process-pass-fd.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const N = 80;
2121
letmessageCallbackCount=0;
2222

2323
functionforkWorker(){
24-
constmessageCallback=(msg,handle)=>{
24+
constmessageCallback=common.mustCall((msg,handle)=>{
2525
messageCallbackCount++;
2626
assert.strictEqual(msg,'handle');
2727
assert.ok(handle);
@@ -32,11 +32,11 @@ function forkWorker(){
3232
recvData+=data;
3333
}));
3434

35-
handle.on('end',()=>{
35+
handle.on('end',common.mustCall(()=>{
3636
assert.strictEqual(recvData,'hello');
3737
worker.kill();
38-
});
39-
};
38+
}));
39+
});
4040

4141
constworker=fork(__filename,['child']);
4242
worker.on('error',(err)=>{
@@ -70,13 +70,13 @@ if (process.argv[2] !== 'child'){
7070
// thus no work to do, and will exit immediately, preventing process leaks.
7171
process.on('message',common.mustCall());
7272

73-
constserver=net.createServer((c)=>{
74-
process.once('message',(msg)=>{
73+
constserver=net.createServer(common.mustCall((c)=>{
74+
process.once('message',common.mustCall((msg)=>{
7575
assert.strictEqual(msg,'got');
7676
c.end('hello');
77-
});
77+
}));
7878
socketConnected();
79-
}).unref();
79+
})).unref();
8080
server.listen(0,common.localhostIPv4,()=>{
8181
const{ port }=server.address();
8282
socket=net.connect(port,common.localhostIPv4,socketConnected).unref();

‎test/sequential/test-cluster-send-handle-large-payload.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ if (cluster.isPrimary){
2323
server.listen(0,common.mustCall(()=>{
2424
constport=server.address().port;
2525
constsocket=newnet.Socket();
26-
socket.connect(port,(err)=>{
27-
assert.ifError(err);
26+
socket.connect(port,common.mustSucceed(()=>{
2827
worker.send({ payload },socket);
29-
});
28+
}));
3029
}));
3130
}else{
3231
process.on('message',common.mustCall(({payload: received},handle)=>{

‎test/sequential/test-debugger-pid.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const{spawn } = require('child_process');
1111

1212
constscript=fixtures.path('debugger','alive.js');
1313

14-
construnTest=async()=>{
14+
(async()=>{
1515
consttarget=spawn(process.execPath,[script]);
1616
constcli=startCLI(['-p',`${target.pid}`],[],{},{randomPort: false});
1717

@@ -24,12 +24,8 @@ const runTest = async () =>{
2424
cli.output,
2525
/>3{3}\+\+x;/,
2626
'marks the 3rd line');
27-
}catch(error){
28-
assert.ifError(error);
2927
}finally{
3028
awaitcli.quit();
3129
target.kill();
3230
}
33-
};
34-
35-
runTest().then(common.mustCall());
31+
})().then(common.mustCall());

‎test/sequential/test-deprecation-flags.js‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
constcommon=require('../common');
2424
constfixtures=require('../common/fixtures');
2525
constassert=require('assert');
2626
constexecFile=require('child_process').execFile;
@@ -40,49 +40,43 @@ const normal = [depmod];
4040
constnoDep=['--no-deprecation',depmod];
4141
consttraceDep=['--trace-deprecation',depmod];
4242

43-
execFile(node,normal,function(er,stdout,stderr){
43+
execFile(node,normal,common.mustSucceed((stdout,stderr)=>{
4444
console.error('normal: show deprecation warning');
45-
assert.strictEqual(er,null);
4645
assert.strictEqual(stdout,'');
4746
assert.match(stderr,/thisfunctionisdeprecated/);
4847
console.log('normal ok');
49-
});
48+
}));
5049

51-
execFile(node,noDep,function(er,stdout,stderr){
50+
execFile(node,noDep,common.mustSucceed((stdout,stderr)=>{
5251
console.error('--no-deprecation: silence deprecations');
53-
assert.strictEqual(er,null);
5452
assert.strictEqual(stdout,'');
5553
assert.strictEqual(stderr.trim(),'This is deprecated');
5654
console.log('silent ok');
57-
});
55+
}));
5856

59-
execFile(node,traceDep,function(er,stdout,stderr){
57+
execFile(node,traceDep,common.mustSucceed((stdout,stderr)=>{
6058
console.error('--trace-deprecation: show stack');
61-
assert.strictEqual(er,null);
6259
assert.strictEqual(stdout,'');
6360
conststack=stderr.trim().split('\n');
6461
// Just check the top and bottom.
6562
assert.match(stack[1],/thisfunctionisdeprecated/);
6663
assert.match(stack[0],/Thisisdeprecated/);
6764
console.log('trace ok');
68-
});
65+
}));
6966

70-
execFile(node,[depUserlandFunction],function(er,stdout,stderr){
67+
execFile(node,[depUserlandFunction],common.mustSucceed((stdout,stderr)=>{
7168
console.error('normal: testing deprecated userland function');
72-
assert.strictEqual(er,null);
7369
assert.strictEqual(stdout,'');
7470
assert.match(stderr,/deprecatedFunctionisdeprecated/);
7571
console.error('normal: ok');
76-
});
72+
}));
7773

78-
execFile(node,[depUserlandClass],function(er,stdout,stderr){
79-
assert.strictEqual(er,null);
74+
execFile(node,[depUserlandClass],common.mustSucceed((stdout,stderr)=>{
8075
assert.strictEqual(stdout,'');
8176
assert.match(stderr,/deprecatedClassisdeprecated/);
82-
});
77+
}));
8378

84-
execFile(node,[depUserlandSubClass],function(er,stdout,stderr){
85-
assert.strictEqual(er,null);
79+
execFile(node,[depUserlandSubClass],common.mustSucceed((stdout,stderr)=>{
8680
assert.strictEqual(stdout,'');
8781
assert.match(stderr,/deprecatedClassisdeprecated/);
88-
});
82+
}));

‎test/sequential/test-dgram-pingpong.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ function pingPongTest(port, host){
1414
throwe;
1515
});
1616

17-
server.on('listening',function(){
17+
server.on('listening',common.mustCall(()=>{
1818
console.log(`server listening on ${port}`);
1919

2020
constclient=dgram.createSocket('udp4');
2121

22-
client.on('message',function(msg){
22+
client.on('message',common.mustCall((msg)=>{
2323
assert.strictEqual(msg.toString('ascii'),'PONG');
2424

2525
client.close();
2626
server.close();
27-
});
27+
}));
2828

2929
client.on('error',function(e){
3030
throwe;
@@ -37,7 +37,7 @@ function pingPongTest(port, host){
3737
}
3838

3939
clientSend();
40-
});
40+
}));
4141
server.bind(port,host);
4242
returnserver;
4343
}

‎test/sequential/test-fs-readdir-recursive.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ function assertDirents(dirents){
134134
assert.strictEqual(dirents.length,expected.length);
135135
dirents.sort((a,b)=>(getDirentPath(a)<getDirentPath(b) ? -1 : 1));
136136
assert.deepStrictEqual(
137-
dirents.map((dirent)=>{
137+
dirents.map(common.mustCallAtLeast((dirent)=>{
138138
assert(direntinstanceoffs.Dirent);
139139
assert.notStrictEqual(dirent.name,undefined);
140140
returngetDirentPath(dirent);
141-
}),
141+
})),
142142
expected
143143
);
144144
}

‎test/sequential/test-heapdump-flag-custom-dir.js‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (common.isWindows)
77

88
constassert=require('assert');
99

10-
constvalidateHeapSnapshotFile=()=>{
10+
if(process.argv[2]==='child'){
1111
constfs=require('fs');
1212

1313
assert.strictEqual(process.listenerCount('SIGUSR2'),1);
@@ -31,10 +31,6 @@ const validateHeapSnapshotFile = () =>{
3131
JSON.parse(fs.readFileSync(files[i]));
3232
}
3333
})();
34-
};
35-
36-
if(process.argv[2]==='child'){
37-
validateHeapSnapshotFile();
3834
}else{
3935
// Modify the timezone. So we can check the file date string still returning correctly.
4036
process.env.TZ='America/New_York';

‎test/sequential/test-http-econnrefused.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ const common = require('../common');
3232
consthttp=require('http');
3333
constassert=require('assert');
3434

35-
constserver=http.createServer(function(req,res){
35+
constserver=http.createServer(common.mustCallAtLeast((req,res)=>{
3636
letbody='';
3737

3838
req.setEncoding('utf8');
3939
req.on('data',function(chunk){
4040
body+=chunk;
4141
});
4242

43-
req.on('end',function(){
43+
req.on('end',common.mustCall(()=>{
4444
assert.strictEqual(body,'PING');
4545
res.writeHead(200,{'Connection': 'close'});
4646
res.end('PONG');
47-
});
48-
});
47+
}));
48+
}));
4949

5050

5151
server.on('listening',pingping);
@@ -109,36 +109,36 @@ function ping(){
109109
method: 'POST'
110110
};
111111

112-
constreq=http.request(opt,function(res){
112+
constreq=http.request(opt,common.mustCallAtLeast((res)=>{
113113
letbody='';
114114

115115
res.setEncoding('utf8');
116116
res.on('data',function(chunk){
117117
body+=chunk;
118118
});
119119

120-
res.on('end',function(){
120+
res.on('end',common.mustCall(()=>{
121121
assert.strictEqual(body,'PONG');
122122
assert.ok(!hadError);
123123
gotEnd=true;
124124
afterPing('success');
125-
});
126-
});
125+
}));
126+
},0));
127127

128128
req.end('PING');
129129

130130
letgotEnd=false;
131131
lethadError=false;
132132

133-
req.on('error',function(error){
133+
req.on('error',common.mustCallAtLeast((error)=>{
134134
console.log(`Error making ping req: ${error}`);
135135
hadError=true;
136136
assert.ok(!gotEnd);
137137

138138
// Family autoselection might be skipped if only a single address is returned by DNS.
139139
constactualError=Array.isArray(error.errors) ? error.errors[0] : error;
140140
afterPing(actualError.message);
141-
});
141+
},0));
142142
}
143143

144144

0 commit comments

Comments
(0)