test: ensure assertions are reachable in test/sequential

PR-URL: https://github.com/nodejs/node/pull/60412
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Antoine du Hamel 2025-10-25 23:49:42 +02:00
parent 53e325ffd0
commit 646e19e2b4
No known key found for this signature in database
GPG Key ID: 20B1A390B168D356
33 changed files with 118 additions and 139 deletions

View File

@ -178,6 +178,7 @@ export default [
'pummel', 'pummel',
'report', 'report',
'sea', 'sea',
'sequential',
'sqlite', 'sqlite',
'system-ca', 'system-ca',
'test426', 'test426',

View File

@ -147,9 +147,9 @@ const args = [
assert.strictEqual(typeof err.pid, 'number'); assert.strictEqual(typeof err.pid, 'number');
spawnSyncKeys spawnSyncKeys
.filter((key) => key !== 'pid') .filter((key) => key !== 'pid')
.forEach((key) => { .forEach(common.mustCallAtLeast((key) => {
assert.deepStrictEqual(err[key], spawnSyncResult[key]); assert.deepStrictEqual(err[key], spawnSyncResult[key]);
}); }));
return true; return true;
}); });
} }

View File

@ -21,7 +21,7 @@ const N = 80;
let messageCallbackCount = 0; let messageCallbackCount = 0;
function forkWorker() { function forkWorker() {
const messageCallback = (msg, handle) => { const messageCallback = common.mustCall((msg, handle) => {
messageCallbackCount++; messageCallbackCount++;
assert.strictEqual(msg, 'handle'); assert.strictEqual(msg, 'handle');
assert.ok(handle); assert.ok(handle);
@ -32,11 +32,11 @@ function forkWorker() {
recvData += data; recvData += data;
})); }));
handle.on('end', () => { handle.on('end', common.mustCall(() => {
assert.strictEqual(recvData, 'hello'); assert.strictEqual(recvData, 'hello');
worker.kill(); worker.kill();
}));
}); });
};
const worker = fork(__filename, ['child']); const worker = fork(__filename, ['child']);
worker.on('error', (err) => { worker.on('error', (err) => {
@ -70,13 +70,13 @@ if (process.argv[2] !== 'child') {
// thus no work to do, and will exit immediately, preventing process leaks. // thus no work to do, and will exit immediately, preventing process leaks.
process.on('message', common.mustCall()); process.on('message', common.mustCall());
const server = net.createServer((c) => { const server = net.createServer(common.mustCall((c) => {
process.once('message', (msg) => { process.once('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'got'); assert.strictEqual(msg, 'got');
c.end('hello'); c.end('hello');
}); }));
socketConnected(); socketConnected();
}).unref(); })).unref();
server.listen(0, common.localhostIPv4, () => { server.listen(0, common.localhostIPv4, () => {
const { port } = server.address(); const { port } = server.address();
socket = net.connect(port, common.localhostIPv4, socketConnected).unref(); socket = net.connect(port, common.localhostIPv4, socketConnected).unref();

View File

@ -23,10 +23,9 @@ if (cluster.isPrimary) {
server.listen(0, common.mustCall(() => { server.listen(0, common.mustCall(() => {
const port = server.address().port; const port = server.address().port;
const socket = new net.Socket(); const socket = new net.Socket();
socket.connect(port, (err) => { socket.connect(port, common.mustSucceed(() => {
assert.ifError(err);
worker.send({ payload }, socket); worker.send({ payload }, socket);
}); }));
})); }));
} else { } else {
process.on('message', common.mustCall(({ payload: received }, handle) => { process.on('message', common.mustCall(({ payload: received }, handle) => {

View File

@ -11,7 +11,7 @@ const { spawn } = require('child_process');
const script = fixtures.path('debugger', 'alive.js'); const script = fixtures.path('debugger', 'alive.js');
const runTest = async () => { (async () => {
const target = spawn(process.execPath, [script]); const target = spawn(process.execPath, [script]);
const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false }); const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false });
@ -24,12 +24,8 @@ const runTest = async () => {
cli.output, cli.output,
/> 3 {3}\+\+x;/, /> 3 {3}\+\+x;/,
'marks the 3rd line'); 'marks the 3rd line');
} catch (error) {
assert.ifError(error);
} finally { } finally {
await cli.quit(); await cli.quit();
target.kill(); target.kill();
} }
}; })().then(common.mustCall());
runTest().then(common.mustCall());

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const fixtures = require('../common/fixtures'); const fixtures = require('../common/fixtures');
const assert = require('assert'); const assert = require('assert');
const execFile = require('child_process').execFile; const execFile = require('child_process').execFile;
@ -40,49 +40,43 @@ const normal = [depmod];
const noDep = ['--no-deprecation', depmod]; const noDep = ['--no-deprecation', depmod];
const traceDep = ['--trace-deprecation', depmod]; const traceDep = ['--trace-deprecation', depmod];
execFile(node, normal, function(er, stdout, stderr) { execFile(node, normal, common.mustSucceed((stdout, stderr) => {
console.error('normal: show deprecation warning'); console.error('normal: show deprecation warning');
assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.match(stderr, /this function is deprecated/); assert.match(stderr, /this function is deprecated/);
console.log('normal ok'); console.log('normal ok');
}); }));
execFile(node, noDep, function(er, stdout, stderr) { execFile(node, noDep, common.mustSucceed((stdout, stderr) => {
console.error('--no-deprecation: silence deprecations'); console.error('--no-deprecation: silence deprecations');
assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.strictEqual(stderr.trim(), 'This is deprecated'); assert.strictEqual(stderr.trim(), 'This is deprecated');
console.log('silent ok'); console.log('silent ok');
}); }));
execFile(node, traceDep, function(er, stdout, stderr) { execFile(node, traceDep, common.mustSucceed((stdout, stderr) => {
console.error('--trace-deprecation: show stack'); console.error('--trace-deprecation: show stack');
assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
const stack = stderr.trim().split('\n'); const stack = stderr.trim().split('\n');
// Just check the top and bottom. // Just check the top and bottom.
assert.match(stack[1], /this function is deprecated/); assert.match(stack[1], /this function is deprecated/);
assert.match(stack[0], /This is deprecated/); assert.match(stack[0], /This is deprecated/);
console.log('trace ok'); console.log('trace ok');
}); }));
execFile(node, [depUserlandFunction], function(er, stdout, stderr) { execFile(node, [depUserlandFunction], common.mustSucceed((stdout, stderr) => {
console.error('normal: testing deprecated userland function'); console.error('normal: testing deprecated userland function');
assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.match(stderr, /deprecatedFunction is deprecated/); assert.match(stderr, /deprecatedFunction is deprecated/);
console.error('normal: ok'); console.error('normal: ok');
}); }));
execFile(node, [depUserlandClass], function(er, stdout, stderr) { execFile(node, [depUserlandClass], common.mustSucceed((stdout, stderr) => {
assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.match(stderr, /deprecatedClass is deprecated/); assert.match(stderr, /deprecatedClass is deprecated/);
}); }));
execFile(node, [depUserlandSubClass], function(er, stdout, stderr) { execFile(node, [depUserlandSubClass], common.mustSucceed((stdout, stderr) => {
assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.match(stderr, /deprecatedClass is deprecated/); assert.match(stderr, /deprecatedClass is deprecated/);
}); }));

View File

@ -14,17 +14,17 @@ function pingPongTest(port, host) {
throw e; throw e;
}); });
server.on('listening', function() { server.on('listening', common.mustCall(() => {
console.log(`server listening on ${port}`); console.log(`server listening on ${port}`);
const client = dgram.createSocket('udp4'); const client = dgram.createSocket('udp4');
client.on('message', function(msg) { client.on('message', common.mustCall((msg) => {
assert.strictEqual(msg.toString('ascii'), 'PONG'); assert.strictEqual(msg.toString('ascii'), 'PONG');
client.close(); client.close();
server.close(); server.close();
}); }));
client.on('error', function(e) { client.on('error', function(e) {
throw e; throw e;
@ -37,7 +37,7 @@ function pingPongTest(port, host) {
} }
clientSend(); clientSend();
}); }));
server.bind(port, host); server.bind(port, host);
return server; return server;
} }

View File

@ -134,11 +134,11 @@ function assertDirents(dirents) {
assert.strictEqual(dirents.length, expected.length); assert.strictEqual(dirents.length, expected.length);
dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1)); dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1));
assert.deepStrictEqual( assert.deepStrictEqual(
dirents.map((dirent) => { dirents.map(common.mustCallAtLeast((dirent) => {
assert(dirent instanceof fs.Dirent); assert(dirent instanceof fs.Dirent);
assert.notStrictEqual(dirent.name, undefined); assert.notStrictEqual(dirent.name, undefined);
return getDirentPath(dirent); return getDirentPath(dirent);
}), })),
expected expected
); );
} }

View File

@ -7,7 +7,7 @@ if (common.isWindows)
const assert = require('assert'); const assert = require('assert');
const validateHeapSnapshotFile = () => { if (process.argv[2] === 'child') {
const fs = require('fs'); const fs = require('fs');
assert.strictEqual(process.listenerCount('SIGUSR2'), 1); assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
@ -31,10 +31,6 @@ const validateHeapSnapshotFile = () => {
JSON.parse(fs.readFileSync(files[i])); JSON.parse(fs.readFileSync(files[i]));
} }
})(); })();
};
if (process.argv[2] === 'child') {
validateHeapSnapshotFile();
} else { } else {
// Modify the timezone. So we can check the file date string still returning correctly. // Modify the timezone. So we can check the file date string still returning correctly.
process.env.TZ = 'America/New_York'; process.env.TZ = 'America/New_York';

View File

@ -32,7 +32,7 @@ const common = require('../common');
const http = require('http'); const http = require('http');
const assert = require('assert'); const assert = require('assert');
const server = http.createServer(function(req, res) { const server = http.createServer(common.mustCallAtLeast((req, res) => {
let body = ''; let body = '';
req.setEncoding('utf8'); req.setEncoding('utf8');
@ -40,12 +40,12 @@ const server = http.createServer(function(req, res) {
body += chunk; body += chunk;
}); });
req.on('end', function() { req.on('end', common.mustCall(() => {
assert.strictEqual(body, 'PING'); assert.strictEqual(body, 'PING');
res.writeHead(200, { 'Connection': 'close' }); res.writeHead(200, { 'Connection': 'close' });
res.end('PONG'); res.end('PONG');
}); }));
}); }));
server.on('listening', pingping); server.on('listening', pingping);
@ -109,7 +109,7 @@ function ping() {
method: 'POST' method: 'POST'
}; };
const req = http.request(opt, function(res) { const req = http.request(opt, common.mustCallAtLeast((res) => {
let body = ''; let body = '';
res.setEncoding('utf8'); res.setEncoding('utf8');
@ -117,20 +117,20 @@ function ping() {
body += chunk; body += chunk;
}); });
res.on('end', function() { res.on('end', common.mustCall(() => {
assert.strictEqual(body, 'PONG'); assert.strictEqual(body, 'PONG');
assert.ok(!hadError); assert.ok(!hadError);
gotEnd = true; gotEnd = true;
afterPing('success'); afterPing('success');
}); }));
}); }, 0));
req.end('PING'); req.end('PING');
let gotEnd = false; let gotEnd = false;
let hadError = false; let hadError = false;
req.on('error', function(error) { req.on('error', common.mustCallAtLeast((error) => {
console.log(`Error making ping req: ${error}`); console.log(`Error making ping req: ${error}`);
hadError = true; hadError = true;
assert.ok(!gotEnd); assert.ok(!gotEnd);
@ -138,7 +138,7 @@ function ping() {
// Family autoselection might be skipped if only a single address is returned by DNS. // Family autoselection might be skipped if only a single address is returned by DNS.
const actualError = Array.isArray(error.errors) ? error.errors[0] : error; const actualError = Array.isArray(error.errors) ? error.errors[0] : error;
afterPing(actualError.message); afterPing(actualError.message);
}); }, 0));
} }

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const http = require('http'); const http = require('http');
@ -33,7 +33,7 @@ const server = http.createServer(function(req, res) {
} }
res.end(req.url); res.end(req.url);
}); });
server.listen(0, function() { server.listen(0, common.mustCall(() => {
const agent = http.Agent({ const agent = http.Agent({
keepAlive: true, keepAlive: true,
maxSockets: 5, maxSockets: 5,
@ -41,16 +41,14 @@ server.listen(0, function() {
}); });
let closed = false; let closed = false;
makeReqs(10, function(er) { makeReqs(10, common.mustSucceed(() => {
assert.ifError(er);
assert.strictEqual(count(agent.freeSockets), 2); assert.strictEqual(count(agent.freeSockets), 2);
assert.strictEqual(count(agent.sockets), 0); assert.strictEqual(count(agent.sockets), 0);
assert.strictEqual(serverSockets.length, 5); assert.strictEqual(serverSockets.length, 5);
// Now make 10 more reqs. // Now make 10 more reqs.
// should use the 2 free reqs from the pool first. // should use the 2 free reqs from the pool first.
makeReqs(10, function(er) { makeReqs(10, common.mustSucceed(() => {
assert.ifError(er);
assert.strictEqual(count(agent.freeSockets), 2); assert.strictEqual(count(agent.freeSockets), 2);
assert.strictEqual(count(agent.sockets), 0); assert.strictEqual(count(agent.sockets), 0);
assert.strictEqual(serverSockets.length, 8); assert.strictEqual(serverSockets.length, 8);
@ -59,8 +57,8 @@ server.listen(0, function() {
server.close(function() { server.close(function() {
closed = true; closed = true;
}); });
}); }));
}); }));
process.on('exit', function() { process.on('exit', function() {
assert(closed); assert(closed);
@ -86,17 +84,17 @@ server.listen(0, function() {
port: server.address().port, port: server.address().port,
path: `/${i}`, path: `/${i}`,
agent: agent agent: agent
}, function(res) { }, common.mustCall((res) => {
let data = ''; let data = '';
res.setEncoding('ascii'); res.setEncoding('ascii');
res.on('data', function(c) { res.on('data', function(c) {
data += c; data += c;
}); });
res.on('end', function() { res.on('end', common.mustCall(() => {
assert.strictEqual(data, `/${i}`); assert.strictEqual(data, `/${i}`);
cb(); cb();
}); }));
}).end(); })).end();
} }
function count(sockets) { function count(sockets) {
@ -104,4 +102,4 @@ server.listen(0, function() {
return n + sockets[name].length; return n + sockets[name].length;
}, 0); }, 0);
} }
}); }));

View File

@ -27,7 +27,7 @@ server.listen(0, common.mustCall(() => {
{ {
const req = client.request(); const req = client.request();
req.on('response', () => { req.on('response', common.mustCall(() => {
// This one should be rejected because the server is over budget // This one should be rejected because the server is over budget
// on the current memory allocation // on the current memory allocation
const req = client.request(); const req = client.request();
@ -40,7 +40,7 @@ server.listen(0, common.mustCall(() => {
server.close(); server.close();
client.destroy(); client.destroy();
})); }));
}); }));
req.resume(); req.resume();
req.on('close', common.mustCall()); req.on('close', common.mustCall());

View File

@ -21,11 +21,11 @@ let interval;
server.on('stream', common.mustNotCall()); server.on('stream', common.mustNotCall());
server.on('session', common.mustCall((session) => { server.on('session', common.mustCall((session) => {
session.on('error', (e) => { session.on('error', common.mustCallAtLeast((e) => {
assert.strictEqual(e.code, 'ERR_HTTP2_ERROR'); assert.strictEqual(e.code, 'ERR_HTTP2_ERROR');
assert(e.message.includes('Flooding was detected')); assert(e.message.includes('Flooding was detected'));
clearInterval(interval); clearInterval(interval);
}); }, 0));
session.on('close', common.mustCall(() => { session.on('close', common.mustCall(() => {
server.close(); server.close();
})); }));

View File

@ -20,11 +20,11 @@ let interval;
server.on('stream', common.mustNotCall()); server.on('stream', common.mustNotCall());
server.on('session', common.mustCall((session) => { server.on('session', common.mustCall((session) => {
session.on('error', (e) => { session.on('error', common.mustCallAtLeast((e) => {
assert.strictEqual(e.code, 'ERR_HTTP2_ERROR'); assert.strictEqual(e.code, 'ERR_HTTP2_ERROR');
assert(e.message.includes('Flooding was detected')); assert(e.message.includes('Flooding was detected'));
clearInterval(interval); clearInterval(interval);
}); }, 0));
session.on('close', common.mustCall(() => { session.on('close', common.mustCall(() => {
server.close(); server.close();

View File

@ -47,9 +47,9 @@ server.on('stream', common.mustCall((stream) => {
stream.end(); stream.end();
})); }));
server.setTimeout(serverTimeout); server.setTimeout(serverTimeout);
server.on('timeout', () => { server.on('timeout', common.mustCallAtLeast(() => {
assert.ok(!didReceiveData, 'Should not timeout'); assert.ok(!didReceiveData, 'Should not timeout');
}); }, 0));
server.listen(0, common.mustCall(() => { server.listen(0, common.mustCall(() => {
const client = http2.connect(`https://localhost:${server.address().port}`, const client = http2.connect(`https://localhost:${server.address().port}`,

View File

@ -28,6 +28,9 @@ const server = http2.createSecureServer({
key: fixtures.readKey('agent1-key.pem'), key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem') cert: fixtures.readKey('agent1-cert.pem')
}); });
const onTimeout = common.mustCallAtLeast(() => {
assert.ok(!didReceiveData, 'Should not timeout');
}, 0);
server.on('stream', common.mustCall((stream) => { server.on('stream', common.mustCall((stream) => {
const content = Buffer.alloc(writeSize, 0x44); const content = Buffer.alloc(writeSize, 0x44);
@ -39,15 +42,11 @@ server.on('stream', common.mustCall((stream) => {
stream.write(content); stream.write(content);
stream.setTimeout(serverTimeout); stream.setTimeout(serverTimeout);
stream.on('timeout', () => { stream.on('timeout', onTimeout);
assert.ok(!didReceiveData, 'Should not timeout');
});
stream.end(); stream.end();
})); }));
server.setTimeout(serverTimeout); server.setTimeout(serverTimeout);
server.on('timeout', () => { server.on('timeout', onTimeout);
assert.ok(!didReceiveData, 'Should not timeout');
});
server.listen(0, common.mustCall(() => { server.listen(0, common.mustCall(() => {
const client = http2.connect(`https://localhost:${server.address().port}`, const client = http2.connect(`https://localhost:${server.address().port}`,

View File

@ -34,11 +34,11 @@ if (process.env.BE_CHILD) {
function wasDisposedWhenOpenHandler(msg) { function wasDisposedWhenOpenHandler(msg) {
assert.strictEqual(msg.cmd, 'url'); assert.strictEqual(msg.cmd, 'url');
assert.strictEqual(msg.url, undefined); assert.strictEqual(msg.url, undefined);
ping(firstPort, (err) => { ping(firstPort, common.mustCall((err) => {
assert(err, 'expected ping to inspector port to fail'); assert(err, 'expected ping to inspector port to fail');
child.send({ cmd: 'dispose' }); child.send({ cmd: 'dispose' });
child.once('message', common.mustCall(wasReDisposedHandler)); child.once('message', common.mustCall(wasReDisposedHandler));
}); }));
} }
function wasReDisposedHandler(msg) { function wasReDisposedHandler(msg) {

View File

@ -165,13 +165,13 @@ try {
assert.strictEqual(path.dirname(__filename), __dirname); assert.strictEqual(path.dirname(__filename), __dirname);
console.error('load custom file types with extensions'); console.error('load custom file types with extensions');
require.extensions['.test'] = function(module, filename) { require.extensions['.test'] = common.mustCall(function(module, filename) {
let content = fs.readFileSync(filename).toString(); let content = fs.readFileSync(filename).toString();
assert.strictEqual(content, 'this is custom source\n'); assert.strictEqual(content, 'this is custom source\n');
content = content.replace('this is custom source', content = content.replace('this is custom source',
'exports.test = \'passed\''); 'exports.test = \'passed\'');
module._compile(content, filename); module._compile(content, filename);
}; });
assert.strictEqual(require('../fixtures/registerExt').test, 'passed'); assert.strictEqual(require('../fixtures/registerExt').test, 'passed');
// Unknown extension, load as .js // Unknown extension, load as .js

View File

@ -40,7 +40,7 @@ const server = net.createServer().listen(0, common.mustCall(() => {
function pummel() { function pummel() {
let pending; let pending;
for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) { for (pending = 0; pending < ATTEMPTS_PER_ROUND; pending++) {
net.createConnection({ port, autoSelectFamily: false }).on('error', function(error) { net.createConnection({ port, autoSelectFamily: false }).on('error', common.mustCallAtLeast((error) => {
// Family autoselection might be skipped if only a single address is returned by DNS. // Family autoselection might be skipped if only a single address is returned by DNS.
const actualError = Array.isArray(error.errors) ? error.errors[0] : error; const actualError = Array.isArray(error.errors) ? error.errors[0] : error;
@ -50,7 +50,7 @@ function pummel() {
if (rounds === ROUNDS) return check(); if (rounds === ROUNDS) return check();
rounds++; rounds++;
pummel(); pummel();
}); }, 0));
reqs++; reqs++;
} }
} }

View File

@ -3,18 +3,18 @@ const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const net = require('net'); const net = require('net');
const server = net.createServer(function(socket) { const server = net.createServer(common.mustCall((socket) => {
assert.strictEqual(socket.remotePort, common.PORT); assert.strictEqual(socket.remotePort, common.PORT);
socket.end(); socket.end();
socket.on('close', function() { socket.on('close', function() {
server.close(); server.close();
}); });
}).listen(0).on('listening', function() { })).listen(0).on('listening', common.mustCall(function() {
const client = net.connect({ const client = net.connect({
host: '127.0.0.1', host: '127.0.0.1',
port: this.address().port, port: this.address().port,
localPort: common.PORT, localPort: common.PORT,
}).on('connect', function() { }).on('connect', common.mustCall(() => {
assert.strictEqual(client.localPort, common.PORT); assert.strictEqual(client.localPort, common.PORT);
}); }));
}); }));

View File

@ -20,7 +20,7 @@ const net = require('net');
server.listen(common.PORT); server.listen(common.PORT);
setTimeout(function() { setTimeout(common.mustCall(() => {
const address = server.address(); const address = server.address();
assert.strictEqual(address.port, common.PORT); assert.strictEqual(address.port, common.PORT);
@ -30,7 +30,7 @@ const net = require('net');
assert.strictEqual(server._connectionKey, `4:0.0.0.0:${address.port}`); assert.strictEqual(server._connectionKey, `4:0.0.0.0:${address.port}`);
server.close(); server.close();
}, 100); }), 100);
} }
// Callback to listen() // Callback to listen()

View File

@ -57,9 +57,7 @@ const web = http.Server(common.mustCall((req, res) => {
res.end(); res.end();
})); }));
req.connection.on('error', (e) => { req.connection.on('error', common.mustNotCall());
assert.ifError(e);
});
})); }));
web.listen(webPort, startClient); web.listen(webPort, startClient);
@ -70,21 +68,19 @@ const tcp = net.Server(common.mustCall((s) => {
let i = 0; let i = 0;
s.on('data', (d) => { s.on('data', common.mustCallAtLeast((d) => {
tcpLengthSeen += d.length; tcpLengthSeen += d.length;
for (let j = 0; j < d.length; j++) { for (let j = 0; j < d.length; j++) {
assert.strictEqual(d[j], buffer[i]); assert.strictEqual(d[j], buffer[i]);
i++; i++;
} }
}); }));
s.on('end', common.mustCall(() => { s.on('end', common.mustCall(() => {
s.end(); s.end();
})); }));
s.on('error', (e) => { s.on('error', common.mustNotCall());
assert.ifError(e);
});
})); }));
tcp.listen(tcpPort, startClient); tcp.listen(tcpPort, startClient);

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
const { spawnSync } = require('child_process'); const { spawnSync } = require('child_process');
const { strictEqual } = require('assert'); const assert = require('assert');
// FIXME add sunos support // FIXME add sunos support
if (common.isSunOS) if (common.isSunOS)
@ -19,4 +19,4 @@ if (common.isWindows)
const xs = 'x'.repeat(1024); const xs = 'x'.repeat(1024);
const proc = spawnSync(process.execPath, ['-p', 'process.title', xs]); const proc = spawnSync(process.execPath, ['-p', 'process.title', xs]);
strictEqual(proc.stdout.toString().trim(), process.execPath); assert.strictEqual(proc.stdout.toString().trim(), process.execPath);

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const fixtures = require('../common/fixtures'); const fixtures = require('../common/fixtures');
const assert = require('assert'); const assert = require('assert');
const execFile = require('child_process').execFile; const execFile = require('child_process').execFile;
@ -13,24 +13,24 @@ const traceWarn = ['--trace-warnings', warnmod];
const warningMessage = /^\(.+\)\sWarning: a bad practice warning/; const warningMessage = /^\(.+\)\sWarning: a bad practice warning/;
execFile(node, normal, function(er, stdout, stderr) { execFile(node, normal, common.mustCall((er, stdout, stderr) => {
// Show Process Warnings // Show Process Warnings
assert.strictEqual(er, null); assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.match(stderr, warningMessage); assert.match(stderr, warningMessage);
}); }));
execFile(node, noWarn, function(er, stdout, stderr) { execFile(node, noWarn, common.mustCall((er, stdout, stderr) => {
// Hide Process Warnings // Hide Process Warnings
assert.strictEqual(er, null); assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.doesNotMatch(stderr, warningMessage); assert.doesNotMatch(stderr, warningMessage);
}); }));
execFile(node, traceWarn, function(er, stdout, stderr) { execFile(node, traceWarn, common.mustCall((er, stdout, stderr) => {
// Show Warning Trace // Show Warning Trace
assert.strictEqual(er, null); assert.strictEqual(er, null);
assert.strictEqual(stdout, ''); assert.strictEqual(stdout, '');
assert.match(stderr, warningMessage); assert.match(stderr, warningMessage);
assert.match(stderr, /at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/); assert.match(stderr, /at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/);
}); }));

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
@ -51,9 +51,9 @@ child.stdout.once('data', function() {
} }
}); });
child.on('close', function(c) { child.on('close', common.mustCall((c) => {
assert.strictEqual(c, 0); assert.strictEqual(c, 0);
// Make sure we got 3 throws, in the end. // Make sure we got 3 throws, in the end.
const lastLine = stdout.trim().split(/\r?\n/).pop(); const lastLine = stdout.trim().split(/\r?\n/).pop();
assert.strictEqual(lastLine, '> 3'); assert.strictEqual(lastLine, '> 3');
}); }));

View File

@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const fixtures = require('../common/fixtures'); const fixtures = require('../common/fixtures');
const assert = require('assert'); const assert = require('assert');
@ -58,13 +58,13 @@ class TestWriter extends Stream {
const r = new FSReadable(file); const r = new FSReadable(file);
const w = new TestWriter(); const w = new TestWriter();
w.on('results', function(res) { w.on('results', common.mustCall((res) => {
console.error(res, w.length); console.error(res, w.length);
assert.strictEqual(w.length, size); assert.strictEqual(w.length, size);
assert.deepStrictEqual(res.map(function(c) { assert.deepStrictEqual(res.map(function(c) {
return c.length; return c.length;
}), expectLengths); }), expectLengths);
console.log('ok'); console.log('ok');
}); }));
r.pipe(w); r.pipe(w);

View File

@ -22,7 +22,7 @@
'use strict'; 'use strict';
// Make sure that sync writes to stderr get processed before exiting. // Make sure that sync writes to stderr get processed before exiting.
require('../common'); const common = require('../common');
function parent() { function parent() {
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
@ -36,12 +36,12 @@ function parent() {
err += c; err += c;
}); });
child.on('close', function() { child.on('close', common.mustCall(() => {
assert.strictEqual(err, `child ${c}\nfoo\nbar\nbaz\n`); assert.strictEqual(err, `child ${c}\nfoo\nbar\nbaz\n`);
console.log(`ok ${++i} child #${c}`); console.log(`ok ${++i} child #${c}`);
if (i === children.length) if (i === children.length)
console.log(`1..${i}`); console.log(`1..${i}`);
}); }));
}); });
} }

View File

@ -6,14 +6,14 @@ const assert = require('assert');
const { sleep } = require('internal/util'); const { sleep } = require('internal/util');
let called = false; let called = false;
const t1 = setInterval(() => { const t1 = setInterval(common.mustCallAtLeast(() => {
assert(!called); assert(!called);
called = true; called = true;
setImmediate(common.mustCall(() => { setImmediate(common.mustCall(() => {
clearInterval(t1); clearInterval(t1);
clearInterval(t2); clearInterval(t2);
})); }));
}, 10); }), 10);
const t2 = setInterval(() => { const t2 = setInterval(() => {
sleep(20); sleep(20);

View File

@ -1,23 +1,23 @@
// Flags: --expose-internals // Flags: --expose-internals
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const { sleep } = require('internal/util'); const { sleep } = require('internal/util');
let cntr = 0; let cntr = 0;
let first; let first;
const t = setInterval(() => { const t = setInterval(common.mustCallAtLeast(() => {
cntr++; cntr++;
if (cntr === 1) { if (cntr === 1) {
sleep(100); sleep(100);
// Ensure that the event loop passes before the second interval // Ensure that the event loop passes before the second interval
setImmediate(() => assert.strictEqual(cntr, 1)); setImmediate(common.mustCall(() => assert.strictEqual(cntr, 1)));
first = Date.now(); first = Date.now();
} else if (cntr === 2) { } else if (cntr === 2) {
assert(Date.now() - first < 100); assert(Date.now() - first < 100);
clearInterval(t); clearInterval(t);
} }
}, 100); }), 100);
const t2 = setInterval(() => { const t2 = setInterval(() => {
if (cntr === 2) { if (cntr === 2) {
clearInterval(t2); clearInterval(t2);

View File

@ -36,12 +36,12 @@ let serverOut = '';
server.stderr.on('data', (data) => serverErr += data); server.stderr.on('data', (data) => serverErr += data);
server.stdout.on('data', (data) => serverOut += data); server.stdout.on('data', (data) => serverOut += data);
server.on('error', common.mustNotCall()); server.on('error', common.mustNotCall());
server.on('exit', (code, signal) => { server.on('exit', common.mustCall((code, signal) => {
// Server is expected to be terminated by cleanUp(). // Server is expected to be terminated by cleanUp().
assert.strictEqual(code, null, assert.strictEqual(code, null,
`'${server.spawnfile} ${server.spawnargs.join(' ')}' unexpected exited with output:\n${serverOut}\n${serverErr}`); `'${server.spawnfile} ${server.spawnargs.join(' ')}' unexpected exited with output:\n${serverOut}\n${serverErr}`);
assert.strictEqual(signal, 'SIGTERM'); assert.strictEqual(signal, 'SIGTERM');
}); }));
const cleanUp = (err) => { const cleanUp = (err) => {
clearTimeout(timeout); clearTimeout(timeout);

View File

@ -90,7 +90,7 @@ function doTest() {
client.stdout.on('data', (data) => { client.stdout.on('data', (data) => {
clientOutput += data.toString(); clientOutput += data.toString();
}); });
client.on('exit', (code) => { client.on('exit', common.mustCall((code) => {
let connectionType; let connectionType;
// Log the output for debugging purposes. Don't remove them or otherwise // Log the output for debugging purposes. Don't remove them or otherwise
// the CI output is useless when this test flakes. // the CI output is useless when this test flakes.
@ -120,7 +120,7 @@ function doTest() {
assert.strictEqual(code, 0); assert.strictEqual(code, 0);
assert.strictEqual(connectionType, expectedType); assert.strictEqual(connectionType, expectedType);
cb(connectionType); cb(connectionType);
}); }));
} }
const server = tls.createServer(options, (cleartext) => { const server = tls.createServer(options, (cleartext) => {

View File

@ -2,7 +2,7 @@ import { isWindows } from '../common/index.mjs';
import { spawn } from 'node:child_process'; import { spawn } from 'node:child_process';
import { once } from 'node:events'; import { once } from 'node:events';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { strictEqual } from 'node:assert'; import assert from 'node:assert';
const python = process.env.PYTHON || (isWindows ? 'python' : 'python3'); const python = process.env.PYTHON || (isWindows ? 'python' : 'python3');
@ -21,4 +21,4 @@ const proc = spawn(python, [
}); });
const [code] = await once(proc, 'exit'); const [code] = await once(proc, 'exit');
strictEqual(code, 0); assert.strictEqual(code, 0);

View File

@ -98,7 +98,7 @@ function checkWorkerActive() {
const w = workerELU(); const w = workerELU();
metricsCh.port2.postMessage({ cmd: 'spin', dur: 50 }); metricsCh.port2.postMessage({ cmd: 'spin', dur: 50 });
metricsCh.port2.once('message', (wElu) => { metricsCh.port2.once('message', mustCall((wElu) => {
const w2 = workerELU(w); const w2 = workerELU(w);
assert.ok(w2.active >= 50, `${w2.active} < 50`); assert.ok(w2.active >= 50, `${w2.active} < 50`);
@ -107,7 +107,7 @@ function checkWorkerActive() {
`${idleActive(wElu)} >= ${idleActive(w2)}`); `${idleActive(wElu)} >= ${idleActive(w2)}`);
metricsCh.port2.postMessage({ cmd: 'close' }); metricsCh.port2.postMessage({ cmd: 'close' });
}); }));
} }
function idleActive(elu) { function idleActive(elu) {