8000 test: ensure assertions are reached on more tests by aduh95 · Pull Request #60498 · nodejs/node · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ export default [
'wpt',
].join(',')}}/**/*.{js,mjs,cjs}`,
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 3 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
},${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
}}.{js,mjs,cjs}`,
],
rules: {
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-child-process-bad-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ function createChild(options, callback) {
}

test('normal execution of a child process is handled', (_, done) => {
createChild({}, (err, stdout, stderr) => {
createChild({}, common.mustCall((err, stdout, stderr) => {
assert.strictEqual(err, null);
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
done();
});
}));
});

test('execution with an error event is handled', (_, done) => {
const error = new Error('foo');
const child = createChild({}, (err, stdout, stderr) => {
const child = createChild({}, common.mustCall((err, stdout, stderr) => {
assert.strictEqual(err, error);
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
done();
});
}));

child.emit('error', error);
});

test('execution with a killed process is handled', (_, done) => {
createChild({ timeout: 1 }, (err, stdout, stderr) => {
createChild({ timeout: 1 }, common.mustCall((err, stdout, stderr) => {
assert.strictEqual(err.killed, true);
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
done();
});
}));
});
A3DB
6 changes: 3 additions & 3 deletions test/parallel/test-child-process-can-write-to-stdout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Tests that a spawned child process can write to stdout without throwing.
// See https://github.com/nodejs/node-v0.x-archive/issues/1899.

require('../common');
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const spawn = require('child_process').spawn;
Expand All @@ -16,7 +16,7 @@ child.stdout.on('data', function(data) {
output += data;
});

child.on('exit', function(code, signal) {
child.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
assert.strictEqual(output, 'hello, world!\n');
});
}));
8 changes: 4 additions & 4 deletions test/parallel/test-child-process-cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const { spawn } = require('child_process');
// - whether the child pid is undefined or number,
// - whether the exit code equals expectCode,
// - optionally whether the trimmed stdout result matches expectData
function testCwd(options, expectPidType, expectCode = 0, expectData) {
function testCwd(options, expectPidType, expectCode = 0, expectData, shouldCallExit = true) {
const child = spawn(...common.pwdCommand, options);

assert.strictEqual(typeof child.pid, expectPidType);
Expand All @@ -47,9 +47,9 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) {

// Can't assert callback, as stayed in to API:
// _The 'exit' event may or may not fire after an error has occurred._
child.on('exit', function(code, signal) {
child.on('exit', shouldCallExit ? common.mustCall((code) => {
assert.strictEqual(code, expectCode);
});
}) : common.mustNotCall());

child.on('close', common.mustCall(function() {
if (expectData) {
Expand All @@ -68,7 +68,7 @@ function testCwd(options, expectPidType, expectCode = 0, expectData) {

// Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT
{
testCwd({ cwd: 'does-not-exist' }, 'undefined', -1)
testCwd({ cwd: 'does-not-exist' }, 'undefined', -1, undefined, false)
.on('error', common.mustCall(function(e) {
assert.strictEqual(e.code, 'ENOENT');
}));
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-child-process-disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ if (process.argv[2] === 'child') {

// Check that the 'disconnect' event is deferred to the next event loop tick.
const disconnect = process.disconnect;
process.disconnect = function() {
process.disconnect = common.mustCall(function() {
disconnect.apply(this, arguments);
// If the event is emitted synchronously, we're too late by now.
process.once('disconnect', common.mustCall(disconnectIsNotAsync));
// The funky function name makes it show up legible in mustCall errors.
function disconnectIsNotAsync() {}
};
});

const server = net.createServer();

Expand Down Expand Up @@ -81,13 +81,13 @@ if (process.argv[2] === 'child') {
child.on('exit', common.mustCall());

// When child is listening
child.on('message', function(obj) {
child.on('message', common.mustCallAtLeast((obj) => {
if (obj && obj.msg === 'ready') {

// Connect to child using TCP to know if disconnect was emitted
const socket = net.connect(obj.port);

socket.on('data', function(data) {
socket.on('data', common.mustCallAtLeast((data) => {
data = data.toString();

// Ready to be disconnected
Expand All @@ -103,10 +103,10 @@ if (process.argv[2] === 'child') {

// 'disconnect' is emitted
childFlag = (data === 'true');
});
}));

}
});
}));

process.on('exit', function() {
assert.strictEqual(childFlag, false);
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-child-process-exec-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ if (process.argv[2] === 'child') {
}

// Test default encoding, which should be utf8.
run({}, (stdout, stderr) => {
run({}, common.mustCall((stdout, stderr) => {
assert.strictEqual(typeof stdout, 'string');
assert.strictEqual(typeof stderr, 'string');
assert.strictEqual(stdout, expectedStdout);
assert.strictEqual(stderr, expectedStderr);
});
}));

// Test explicit utf8 encoding.
run({ encoding: 'utf8' }, (stdout, stderr) => {
run({ encoding: 'utf8' }, common.mustCall((stdout, stderr) => {
assert.strictEqual(typeof stdout, 'string');
assert.strictEqual(typeof stderr, 'string');
assert.strictEqual(stdout, expectedStdout);
assert.strictEqual(stderr, expectedStderr);
});
}));

// Test cases that result in buffer encodings.
[undefined, null, 'buffer', 'invalid'].forEach((encoding) => {
run({ encoding }, (stdout, stderr) => {
run({ encoding }, common.mustCall((stdout, stderr) => {
assert(stdout instanceof Buffer);
assert(stdout instanceof Buffer);
assert.strictEqual(stdout.toString(), expectedStdout);
assert.strictEqual(stderr.toString(), expectedStderr);
});
}));
});
}
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-execfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ common.expectWarning(
const ac = new AbortController();
const { signal } = ac;

const test = () => {
const test = common.mustCall(() => {
const check = common.mustCall((err) => {
assert.strictEqual(err.code, 'ABORT_ERR');
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(err.signal, undefined);
});
execFile(process.execPath, [echoFixture, 0], { signal }, check);
};
});

// Verify that it still works the same way now that the signal is aborted.
test();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-flush-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ p.on('close', common.mustCall((code, signal) => {

p.stdout.read();

const spawnWithReadable = () => {
const spawnWithReadable = common.mustCall(() => {
const buffer = [];
const p = cp.spawn('echo', ['123'], opts);
p.on('close', common.mustCall((code, signal) => {
Expand All @@ -30,4 +30,4 @@ const spawnWithReadable = () => {
while ((buf = p.stdout.read()) !== null)
buffer.push(buf);
});
};
});
40 changes: 20 additions & 20 deletions test/parallel/test-child-process-fork-abort-signal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { mustCall, mustNotCall } = require('../common');
const { strictEqual } = require('assert');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const { fork } = require('child_process');

Expand All @@ -13,11 +13,11 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
234B }));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
assert.strictEqual(err.name, 'AbortError');
}));
process.nextTick(() => ac.abort());
}
Expand All @@ -30,13 +30,13 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
strictEqual(err.cause.name, 'Error');
strictEqual(err.cause.message, 'boom');
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(err.cause.name, 'Error');
assert.strictEqual(err.cause.message, 'boom');
}));
process.nextTick(() => ac.abort(new Error('boom')));
}
Expand All @@ -48,11 +48,11 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
assert.strictEqual(err.name, 'AbortError');
}));
}

Expand All @@ -63,13 +63,13 @@ const { fork } = require('child_process');
signal
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGTERM');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGTERM');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
strictEqual(err.cause.name, 'Error');
strictEqual(err.cause.message, 'boom');
assert.strictEqual(err.name, 'AbortError');
assert.strictEqual(err.cause.name, 'Error');
assert.strictEqual(err.cause.message, 'boom');
}));
}

Expand All @@ -81,11 +81,11 @@ const { fork } = require('child_process');
killSignal: 'SIGKILL',
});
cp.on('exit', mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, 'SIGKILL');
assert.strictEqual(code, null);
assert.strictEqual(killSignal, 'SIGKILL');
}));
cp.on('error', mustCall((err) => {
strictEqual(err.name, 'AbortError');
assert.strictEqual(err.name, 'AbortError');
}));
}

Expand Down
13 changes: 6 additions & 7 deletions test/parallel/test-child-process-fork-closed-channel-segfault.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const server = net
s.destroy();
}, 100);
})
.listen(0, function() {
.listen(0, common.mustCall(() => {
const worker = cluster.fork();

worker.on('error', function(err) {
Expand Down Expand Up @@ -70,9 +70,8 @@ const server = net
})
);

worker.on('online', function() {
send(function(err) {
assert.ifError(err);
worker.on('online', common.mustCall(() => {
send(common.mustSucceed(() => {
send(function(err) {
// Ignore errors when sending the second handle because the worker
// may already have exited.
Expand All @@ -83,6 +82,6 @@ const server = net
throw err;
}
});
});
});
});
}));
}));
}));
4 changes: 1 addition & 3 deletions test/parallel/test-child-process-fork-dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ if (process.argv[2] === 'child') {
msg.length,
serverPort,
'127.0.0.1',
(err) => {
assert.ifError(err);
}
common.mustSucceed(),
);
}
}, 1);
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-child-process-fork-net-server.js
234B
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ if (process.argv[2] === 'child') {
// TODO(@jasnell): The close event is not called consistently
// across platforms. Need to investigate if it can be made
// more consistent.
const onClose = (msg) => {
const onClose = common.mustCallAtLeast((msg) => {
if (msg.what !== 'close') return;
process.removeListener('message', onClose);

serverScope.on('close', common.mustCall(() => {
process.send({ what: 'close' });
}));
serverScope.close();
};
});

process.on('message', onClose);

Expand All @@ -86,13 +86,13 @@ if (process.argv[2] === 'child') {
function testServer(callback) {

// Destroy server execute callback when done.
const countdown = new Countdown(2, () => {
const countdown = new Countdown(2, common.mustCall(() => {
server.on('close', common.mustCall(() => {
debug('PARENT: server closed');
child.send({ what: 'close' });
}));
server.close();
});
}));

// We expect 4 connections and close events.
const connections = new Countdown(4, () => countdown.dec());
Expand Down Expand Up @@ -122,7 +122,7 @@ if (process.argv[2] === 'child') {
// event is emitted appears to be variable across platforms.
// Need to investigate why and whether it can be made
// more consistent.
const messageHandlers = (msg) => {
const messageHandlers = common.mustCallAtLeast((msg) => {
if (msg.what === 'listening') {
// Make connections.
let socket;
Expand All @@ -143,7 +143,7 @@ if (process.argv[2] === 'child') {
child.removeListener('message', messageHandlers);
callback();
}
};
});

child.on('message', messageHandlers);
}
Expand Down
Loading
Loading
0