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
2 changes: 1 addition & 1 deletion test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default [
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},${
},n*,${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
}}.{js,mjs,cjs}`,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const { getNavigatorPlatform } = require('internal/navigator');
const { execFile } = require('child_process');

const is = {
number: (value, key) => {
number: common.mustCallAtLeast((value, key) => {
assert(!Number.isNaN(value), `${key} should not be NaN`);
assert.strictEqual(typeof value, 'number');
},
}),
};

is.number(+navigator.hardwareConcurrency, 'hardwareConcurrency');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-autoselectfamily-commandline-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const { createConnection, createServer } = require('net');

// Test that IPV4 is NOT reached if IPV6 is not reachable and the option has been disabled via command line
{
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCallAtLeast((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}, 0));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = ipv4Server.address().port;
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-net-autoselectfamily-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTime

// Test that IPV4 is reached by default if IPV6 is not reachable and the default is enabled
{
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCall((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
setDefaultAutoSelectFamily(true);
Expand Down Expand Up @@ -45,12 +45,12 @@ const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTime

// Test that IPV4 is not reached by default if IPV6 is not reachable and the default is disabled
{
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCallAtLeast((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}, 0));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
setDefaultAutoSelectFamily(false);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-autoselectfamily-ipv4first.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const { createConnection, createServer } = require('net');

// Test that happy eyeballs algorithm is properly implemented when a A record is returned first.
if (common.hasIPv6) {
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCall((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}));

const ipv6Server = createServer((socket) => {
socket.on('data', common.mustNotCall(() => {
Expand Down
16 changes: 8 additions & 8 deletions test/parallel/test-net-autoselectfamily.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTime

// Test that IPV4 is reached if IPV6 is not reachable
{
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCall((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = ipv4Server.address().port;
Expand Down Expand Up @@ -56,12 +56,12 @@ const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTime

// Test that only the last successful connection is established.
{
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCall((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = ipv4Server.address().port;
Expand Down Expand Up @@ -116,12 +116,12 @@ if (common.hasIPv6) {
}));
});

const ipv6Server = createServer((socket) => {
const ipv6Server = createServer(common.mustCall((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv6');
socket.end();
}));
});
}));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = ipv4Server.address().port;
Expand Down Expand Up @@ -184,12 +184,12 @@ if (common.hasIPv6) {

// Test that the option can be disabled
{
const ipv4Server = createServer((socket) => {
const ipv4Server = createServer(common.mustCallAtLeast((socket) => {
socket.on('data', common.mustCall(() => {
socket.write('response-ipv4');
socket.end();
}));
});
}, 0));

ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = ipv4Server.address().port;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-child-process-connect-reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ if (process.argv[2] === 'child') {
}
});

conn.on('error', (err) => {
conn.on('error', common.mustCallAtLeast((err) => {
// Error emitted on Windows.
assert.strictEqual(err.code, 'ECONNRESET');
});
}, 0));

conn.on('connect', common.mustCall(() => {
cp.kill('SIGKILL');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-connect-abort-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ server.listen(0, common.mustCall(async () => {
});
});

const assertAbort = async (socket, testName) => {
const assertAbort = common.mustCallAtLeast(async (socket, testName) => {
try {
await once(socket, 'close');
assert.fail(`close ${testName} should have thrown`);
} catch (err) {
assert.strictEqual(err.name, 'AbortError');
}
};
});

async function postAbort() {
const ac = new AbortController();
Expand Down
10 changes: 4 additions & 6 deletions test/parallel/test-net-connect-keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ const truthyValues = [true, 1, 'true', {}, []];
const delays = [[123, 0], [456123, 456], [-123000, 0], [undefined, 0]];
const falseyValues = [false, 0, ''];

const genSetKeepAlive = (desiredEnable, desiredDelay) => (enable, delay) => {
assert.strictEqual(enable, desiredEnable);
assert.strictEqual(delay, desiredDelay);
};

for (const value of truthyValues) {
for (const delay of delays) {
const server = net.createServer();
Expand All @@ -26,7 +21,10 @@ for (const value of truthyValues) {
);

client._handle.setKeepAlive = common.mustCall(
genSetKeepAlive(true, delay[1])
(enable, actualDelay) => {
assert.strictEqual(enable, true);
assert.strictEqual(actualDelay, delay[1]);
},
);

client.on('end', common.mustCall(function() {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-connect-memleak.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const gcListener = { ongc() { collected = true; } };

function done(sock) {
globalThis.gc();
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(collected, true);
sock.end();
server.close();
});
}));
}
7 changes: 3 additions & 4 deletions test/parallel/test-net-connect-nodelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const net = require('net');

const truthyValues = [true, 1, 'true', {}, []];
const falseyValues = [false, 0, ''];
const genSetNoDelay = (desiredArg) => (enable) => {
assert.strictEqual(enable, desiredArg);
};

for (const value of truthyValues) {
const server = net.createServer();
Expand All @@ -21,7 +18,9 @@ for (const value of truthyValues) {
common.mustCall(() => client.end())
);

client._handle.setNoDelay = common.mustCall(genSetNoDelay(true));
client._handle.setNoDelay = common.mustCall((enable) => {
assert.strictEqual(enable, true);
});

client.on('end', common.mustCall(function() {
server.close();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-connect-options-allowhalfopen.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const net = require('net');
console.log(`'connect' emitted on Client ${index}`);
client.resume();
client.on('end', common.mustCall(function clientOnEnd() {
setTimeout(function closeServer() {
setTimeout(common.mustCall(() => {
// When allowHalfOpen is true, client must still be writable
// after the server closes the connections, but not readable
console.log(`client ${index} received FIN`);
Expand All @@ -77,7 +77,7 @@ const net = require('net');
clientSentFIN++;
console.log(
`client ${index} sent FIN, ${clientSentFIN} have been sent`);
}, 50);
}), 50);
}));
client.on('close', common.mustCall(function clientOnClose() {
clientReceivedFIN++;
Expand Down
13 changes: 6 additions & 7 deletions test/parallel/test-net-connect-options-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function testClients(getSocketOpt, getConnectOpt, getConnectCb) {
}

const CLIENT_VARIANTS = 6; // Same length as array above
const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS);

// Test Pipe fd is wrapped correctly
{
Expand All @@ -42,7 +41,7 @@ const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS);
let socketCounter = 0;
const handleMap = new Map();
const server = net.createServer()
.on('connection', forAllClients(function serverOnConnection(socket) {
.on('connection', common.mustCallAtLeast(function serverOnConnection(socket) {
let clientFd;
socket.on('data', common.mustCall(function(data) {
clientFd = data.toString();
Expand All @@ -59,7 +58,7 @@ const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS);
}, 10);
}
}, 1));
}))
}), CLIENT_VARIANTS)
.on('close', function() {
setTimeout(() => {
for (const pair of handleMap) {
Expand All @@ -73,19 +72,19 @@ const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS);
assert.fail(`[Pipe server]${err}`);
})
.listen({ path: serverPath }, common.mustCall(function serverOnListen() {
const getSocketOpt = (index) => {
const getSocketOpt = common.mustCallAtLeast((index) => {
const handle = new Pipe(PipeConstants.SOCKET);
const err = handle.bind(`${prefix}-client-${socketCounter++}`);
assert(err >= 0, String(err));
assert.notStrictEqual(handle.fd, -1);
handleMap.set(index, handle);
console.error(`[Pipe]Bound handle with Pipe ${handle.fd}`);
return { fd: handle.fd, readable: true, writable: true };
};
});
const getConnectOpt = () => ({
path: serverPath
});
const getConnectCb = (index) => common.mustCall(function clientOnConnect() {
const getConnectCb = common.mustCallAtLeast((index) => common.mustCall(function clientOnConnect() {
// Test if it's wrapping an existing fd
assert(handleMap.has(index));
const oldHandle = handleMap.get(index);
Expand All @@ -96,7 +95,7 @@ const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS);
console.error(err);
assert.fail(`[Pipe Client]${err}`);
});
});
}));

testClients(getSocketOpt, getConnectOpt, getConnectCb);
}));
Expand Down
16 changes: 8 additions & 8 deletions test/parallel/test-net-connect-options-ipv6.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const net = require('net');
const hostAddrIPv6 = '::1';
const HOSTNAME = 'dummy';

const server = net.createServer({ allowHalfOpen: true }, (socket) => {
const server = net.createServer({ allowHalfOpen: true }, common.mustCall((socket) => {
socket.resume();
socket.on('end', common.mustCall());
socket.end();
});
}));

function tryConnect() {
const connectOpt = {
Expand All @@ -51,17 +51,17 @@ function tryConnect() {
})
};
// No `mustCall`, since test could skip, and it's the only path to `close`.
const client = net.connect(connectOpt, () => {
const client = net.connect(connectOpt, common.mustCall(() => {
client.resume();
client.on('end', () => {
client.on('end', common.mustCall(() => {
// Wait for next uv tick and make sure the socket stream is writable.
setTimeout(function() {
setTimeout(common.mustCall(() => {
assert(client.writable);
client.end();
}, 10);
});
}), 10);
}));
client.on('close', () => server.close());
});
}));
}

server.listen(0, hostAddrIPv6, tryConnect);
4 changes: 2 additions & 2 deletions test/parallel/test-net-connect-options-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const CLIENT_VARIANTS = 12;
socket.end('ok');
}, CLIENT_VARIANTS))
.listen(serverPath, common.mustCall(function() {
const getConnectCb = () => common.mustCall(function() {
const getConnectCb = common.mustCallAtLeast(() => common.mustCall(function() {
this.end();
this.on('close', common.mustCall(function() {
counter++;
if (counter === CLIENT_VARIANTS) {
server.close();
}
}));
});
}));

// CLIENT_VARIANTS depends on the following code
net.connect(serverPath, getConnectCb()).resume();
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-net-connect-options-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function syncFailToConnect(port, assertErr, optOnly) {
}

function canConnect(port) {
const noop = () => common.mustCall();
const noop = common.mustCallAtLeast(() => common.mustCall());
const family = 4;

// connect(port, cb) and connect(port)
Expand Down Expand Up @@ -202,10 +202,10 @@ function canConnect(port) {
}

function asyncFailToConnect(port) {
const onError = () => common.mustCall((err) => {
const onError = common.mustCallAtLeast(() => common.mustCall((err) => {
const regexp = /^Error: connect E\w+.+$/;
assert.match(String(err), regexp);
});
}));

const dont = () => common.mustNotCall();
const family = 4;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-eaddrinuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const net = require('net');
const server1 = net.createServer(common.mustNotCall());
const server2 = net.createServer(common.mustNotCall());
server1.listen(0, common.mustCall(function() {
server2.on('error', function(error) {
server2.on('error', common.mustCall((error) => {
assert.strictEqual(error.message.includes('EADDRINUSE'), true);
server1.close();
});
}));
server2.listen(this.address().port);
}));
Loading
Loading