Skip to content

Commit 646e19e

Browse files
committed
test: ensure assertions are reachable in test/sequential
PR-URL: nodejs/node#60412 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 53e325f commit 646e19e

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
@@ -178,6 +178,7 @@ export default [
178178
'pummel',
179179
'report',
180180
'sea',
181+
'sequential',
181182
'sqlite',
182183
'system-ca',
183184
'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(typeof err.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
return true;
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
let messageCallbackCount = 0;
2222

2323
function forkWorker() {
24-
const messageCallback = (msg, handle) => {
24+
const messageCallback = 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
const worker = 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-
const server = net.createServer((c) => {
74-
process.once('message', (msg) => {
73+
const server = 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
const port = server.address().port;
2525
const socket = new net.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
const script = fixtures.path('debugger', 'alive.js');
1313

14-
const runTest = async () => {
14+
(async () => {
1515
const target = spawn(process.execPath, [script]);
1616
const cli = 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
await cli.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+
const common = require('../common');
2424
const fixtures = require('../common/fixtures');
2525
const assert = require('assert');
2626
const execFile = require('child_process').execFile;
@@ -40,49 +40,43 @@ const normal = [depmod];
4040
const noDep = ['--no-deprecation', depmod];
4141
const traceDep = ['--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, /this function is deprecated/);
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
const stack = stderr.trim().split('\n');
6461
// Just check the top and bottom.
6562
assert.match(stack[1], /this function is deprecated/);
6663
assert.match(stack[0], /This is deprecated/);
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, /deprecatedFunction is deprecated/);
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, /deprecatedClass is deprecated/);
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, /deprecatedClass is deprecated/);
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
throw e;
1515
});
1616

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

2020
const client = 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
throw e;
@@ -37,7 +37,7 @@ function pingPongTest(port, host) {
3737
}
3838

3939
clientSend();
40-
});
40+
}));
4141
server.bind(port, host);
4242
return server;
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(dirent instanceof fs.Dirent);
139139
assert.notStrictEqual(dirent.name, undefined);
140140
return getDirentPath(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
const assert = require('assert');
99

10-
const validateHeapSnapshotFile = () => {
10+
if (process.argv[2] === 'child') {
1111
const fs = 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
const http = require('http');
3333
const assert = require('assert');
3434

35-
const server = http.createServer(function(req, res) {
35+
const server = http.createServer(common.mustCallAtLeast((req, res) => {
3636
let body = '';
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-
const req = http.request(opt, function(res) {
112+
const req = http.request(opt, common.mustCallAtLeast((res) => {
113113
let body = '';
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
let gotEnd = false;
131131
let hadError = 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
const actualError = Array.isArray(error.errors) ? error.errors[0] : error;
140140
afterPing(actualError.message);
141-
});
141+
}, 0));
142142
}
143143

144144

0 commit comments

Comments
 (0)