From 4a4fdcf3900a024bea231c81443c24a1a8d5d571 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 17 Nov 2025 23:12:08 +0100 Subject: [PATCH] test: ensure assertions are reached on more tests PR-URL: https://github.com/nodejs/node/pull/60761 Reviewed-By: Colin Ihrig --- test/eslint.config_partial.mjs | 2 +- test/parallel/test-navigator.js | 4 +- ...net-autoselectfamily-commandline-option.js | 4 +- .../test-net-autoselectfamily-default.js | 8 +- .../test-net-autoselectfamily-ipv4first.js | 4 +- test/parallel/test-net-autoselectfamily.js | 16 +-- .../test-net-child-process-connect-reset.js | 4 +- .../test-net-connect-abort-controller.js | 4 +- test/parallel/test-net-connect-keepalive.js | 10 +- test/parallel/test-net-connect-memleak.js | 4 +- test/parallel/test-net-connect-nodelay.js | 7 +- .../test-net-connect-options-allowhalfopen.js | 4 +- test/parallel/test-net-connect-options-fd.js | 13 +- .../parallel/test-net-connect-options-ipv6.js | 16 +-- .../parallel/test-net-connect-options-path.js | 4 +- .../parallel/test-net-connect-options-port.js | 6 +- test/parallel/test-net-eaddrinuse.js | 4 +- test/parallel/test-net-keepalive.js | 4 +- .../test-net-listen-exclusive-random-ports.js | 10 +- test/parallel/test-net-listen-invalid-port.js | 4 +- test/parallel/test-net-localerror.js | 6 +- .../parallel/test-net-onread-static-buffer.js | 48 ++++---- .../parallel/test-net-persistent-keepalive.js | 14 +-- test/parallel/test-net-persistent-nodelay.js | 10 +- .../parallel/test-net-persistent-ref-unref.js | 18 +-- test/parallel/test-net-pipe-with-long-path.js | 8 +- test/parallel/test-net-reconnect.js | 22 ++-- test/parallel/test-net-remote-address-port.js | 24 ++-- test/parallel/test-net-remote-address.js | 8 +- test/parallel/test-net-server-close.js | 4 +- test/parallel/test-net-server-listen-path.js | 4 +- .../test-net-server-listen-remove-callback.js | 6 +- ...-connections-close-makes-more-available.js | 6 +- .../test-net-server-max-connections.js | 12 +- .../test-net-server-pause-on-connect.js | 20 +-- test/parallel/test-net-server-reset.js | 8 +- test/parallel/test-net-settimeout.js | 4 +- .../test-net-socket-close-after-end.js | 8 +- test/parallel/test-net-socket-connecting.js | 10 +- .../test-net-socket-no-halfopen-enforcer.js | 4 +- test/parallel/test-net-socket-setnodelay.js | 8 +- test/parallel/test-net-socket-write-error.js | 4 +- test/parallel/test-net-stream.js | 10 +- test/parallel/test-net-sync-cork.js | 8 +- test/parallel/test-net-throttle.js | 18 +-- test/parallel/test-net-write-after-close.js | 8 +- test/parallel/test-net-write-after-end-nt.js | 8 +- test/parallel/test-next-tick-errors.js | 6 +- test/parallel/test-nodeeventtarget.js | 115 +++++++++--------- 49 files changed, 276 insertions(+), 285 deletions(-) diff --git a/test/eslint.config_partial.mjs b/test/eslint.config_partial.mjs index 4c98c564e07c40..bd54c481a19be8 100644 --- a/test/eslint.config_partial.mjs +++ b/test/eslint.config_partial.mjs @@ -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}`, diff --git a/test/parallel/test-navigator.js b/test/parallel/test-navigator.js index dd2b050935b6ad..01c5595b93cd12 100644 --- a/test/parallel/test-navigator.js +++ b/test/parallel/test-navigator.js @@ -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'); diff --git a/test/parallel/test-net-autoselectfamily-commandline-option.js b/test/parallel/test-net-autoselectfamily-commandline-option.js index bf98d5f756e427..54627a1266edaf 100644 --- a/test/parallel/test-net-autoselectfamily-commandline-option.js +++ b/test/parallel/test-net-autoselectfamily-commandline-option.js @@ -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; diff --git a/test/parallel/test-net-autoselectfamily-default.js b/test/parallel/test-net-autoselectfamily-default.js index b0b41fb7037d2f..67977498c5a34c 100644 --- a/test/parallel/test-net-autoselectfamily-default.js +++ b/test/parallel/test-net-autoselectfamily-default.js @@ -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); @@ -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); diff --git a/test/parallel/test-net-autoselectfamily-ipv4first.js b/test/parallel/test-net-autoselectfamily-ipv4first.js index f94af0d9eeeb81..e7e788a0d2195f 100644 --- a/test/parallel/test-net-autoselectfamily-ipv4first.js +++ b/test/parallel/test-net-autoselectfamily-ipv4first.js @@ -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(() => { diff --git a/test/parallel/test-net-autoselectfamily.js b/test/parallel/test-net-autoselectfamily.js index 180ec9073eac89..0fdac23a6f6e9a 100644 --- a/test/parallel/test-net-autoselectfamily.js +++ b/test/parallel/test-net-autoselectfamily.js @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/test/parallel/test-net-child-process-connect-reset.js b/test/parallel/test-net-child-process-connect-reset.js index 228ba8ed57fccc..ef9245c910ed8b 100644 --- a/test/parallel/test-net-child-process-connect-reset.js +++ b/test/parallel/test-net-child-process-connect-reset.js @@ -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'); diff --git a/test/parallel/test-net-connect-abort-controller.js b/test/parallel/test-net-connect-abort-controller.js index 9c259cc3fc2c15..a073b75db19e1d 100644 --- a/test/parallel/test-net-connect-abort-controller.js +++ b/test/parallel/test-net-connect-abort-controller.js @@ -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(); diff --git a/test/parallel/test-net-connect-keepalive.js b/test/parallel/test-net-connect-keepalive.js index 3e439c647c36be..fb872f04d0f840 100644 --- a/test/parallel/test-net-connect-keepalive.js +++ b/test/parallel/test-net-connect-keepalive.js @@ -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(); @@ -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() { diff --git a/test/parallel/test-net-connect-memleak.js b/test/parallel/test-net-connect-memleak.js index 079e45f7223a8b..de925f5d08c4ed 100644 --- a/test/parallel/test-net-connect-memleak.js +++ b/test/parallel/test-net-connect-memleak.js @@ -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(); - }); + })); } diff --git a/test/parallel/test-net-connect-nodelay.js b/test/parallel/test-net-connect-nodelay.js index 6810e339e2b6c4..ede4ae48053427 100644 --- a/test/parallel/test-net-connect-nodelay.js +++ b/test/parallel/test-net-connect-nodelay.js @@ -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(); @@ -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(); diff --git a/test/parallel/test-net-connect-options-allowhalfopen.js b/test/parallel/test-net-connect-options-allowhalfopen.js index ed615dcf2c4919..26f1ace52e09b6 100644 --- a/test/parallel/test-net-connect-options-allowhalfopen.js +++ b/test/parallel/test-net-connect-options-allowhalfopen.js @@ -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`); @@ -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++; diff --git a/test/parallel/test-net-connect-options-fd.js b/test/parallel/test-net-connect-options-fd.js index e9b35c0bfeadf4..bd761cf0723aa8 100644 --- a/test/parallel/test-net-connect-options-fd.js +++ b/test/parallel/test-net-connect-options-fd.js @@ -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 { @@ -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(); @@ -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) { @@ -73,7 +72,7 @@ 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)); @@ -81,11 +80,11 @@ const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS); 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); @@ -96,7 +95,7 @@ const forAllClients = (cb) => common.mustCall(cb, CLIENT_VARIANTS); console.error(err); assert.fail(`[Pipe Client]${err}`); }); - }); + })); testClients(getSocketOpt, getConnectOpt, getConnectCb); })); diff --git a/test/parallel/test-net-connect-options-ipv6.js b/test/parallel/test-net-connect-options-ipv6.js index 13381074ba46b7..61076085150072 100644 --- a/test/parallel/test-net-connect-options-ipv6.js +++ b/test/parallel/test-net-connect-options-ipv6.js @@ -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 = { @@ -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); diff --git a/test/parallel/test-net-connect-options-path.js b/test/parallel/test-net-connect-options-path.js index 61de8caab15b56..21f6b1ff194e55 100644 --- a/test/parallel/test-net-connect-options-path.js +++ b/test/parallel/test-net-connect-options-path.js @@ -20,7 +20,7 @@ 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++; @@ -28,7 +28,7 @@ const CLIENT_VARIANTS = 12; server.close(); } })); - }); + })); // CLIENT_VARIANTS depends on the following code net.connect(serverPath, getConnectCb()).resume(); diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js index b62fe945784248..c46dbb88aa51bd 100644 --- a/test/parallel/test-net-connect-options-port.js +++ b/test/parallel/test-net-connect-options-port.js @@ -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) @@ -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; diff --git a/test/parallel/test-net-eaddrinuse.js b/test/parallel/test-net-eaddrinuse.js index 201728464ed9a1..dd13ed1ee46609 100644 --- a/test/parallel/test-net-eaddrinuse.js +++ b/test/parallel/test-net-eaddrinuse.js @@ -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); })); diff --git a/test/parallel/test-net-keepalive.js b/test/parallel/test-net-keepalive.js index d91ec625f88246..26a4c5b3d64841 100644 --- a/test/parallel/test-net-keepalive.js +++ b/test/parallel/test-net-keepalive.js @@ -26,7 +26,7 @@ const net = require('net'); let serverConnection; let clientConnection; -const echoServer = net.createServer(function(connection) { +const echoServer = net.createServer(common.mustCall((connection) => { serverConnection = connection; setTimeout(common.mustCall(function() { // Make sure both connections are still open @@ -43,7 +43,7 @@ const echoServer = net.createServer(function(connection) { connection.on('end', function() { connection.end(); }); -}); +})); echoServer.listen(0); echoServer.on('listening', function() { diff --git a/test/parallel/test-net-listen-exclusive-random-ports.js b/test/parallel/test-net-listen-exclusive-random-ports.js index b9e92a750dbb64..3604e2481ccdb0 100644 --- a/test/parallel/test-net-listen-exclusive-random-ports.js +++ b/test/parallel/test-net-listen-exclusive-random-ports.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); const net = require('net'); @@ -8,19 +8,19 @@ const net = require('net'); if (cluster.isPrimary) { const worker1 = cluster.fork(); - worker1.on('message', function(port1) { + worker1.on('message', common.mustCall((port1) => { assert.strictEqual(port1, port1 | 0, `first worker could not listen on port ${port1}`); const worker2 = cluster.fork(); - worker2.on('message', function(port2) { + worker2.on('message', common.mustCall((port2) => { assert.strictEqual(port2, port2 | 0, `second worker could not listen on port ${port2}`); assert.notStrictEqual(port1, port2); worker1.kill(); worker2.kill(); - }); - }); + })); + })); } else { const server = net.createServer(() => {}); diff --git a/test/parallel/test-net-listen-invalid-port.js b/test/parallel/test-net-listen-invalid-port.js index 844878036646dd..220ca2ba30b065 100644 --- a/test/parallel/test-net-listen-invalid-port.js +++ b/test/parallel/test-net-listen-invalid-port.js @@ -10,13 +10,13 @@ const net = require('net'); const invalidPort = -1 >>> 0; -net.Server().listen(0, function() { +net.Server().listen(0, common.mustCall(function() { const address = this.address(); const key = `${address.family.slice(-1)}:${address.address}:0`; assert.strictEqual(this._connectionKey, key); this.close(); -}); +})); // The first argument is a configuration object assert.throws(() => { diff --git a/test/parallel/test-net-localerror.js b/test/parallel/test-net-localerror.js index 92095340512d85..ab31c992556e3a 100644 --- a/test/parallel/test-net-localerror.js +++ b/test/parallel/test-net-localerror.js @@ -20,16 +20,16 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); -const connect = (opts, code, type) => { +const connect = common.mustCall((opts, code, type) => { assert.throws( () => net.connect(opts), { code, name: type.name } ); -}; +}, 2); connect({ host: 'localhost', diff --git a/test/parallel/test-net-onread-static-buffer.js b/test/parallel/test-net-onread-static-buffer.js index ce722f69cd7fa3..7433ea4fe51292 100644 --- a/test/parallel/test-net-onread-static-buffer.js +++ b/test/parallel/test-net-onread-static-buffer.js @@ -9,7 +9,7 @@ const message = Buffer.from('hello world'); net.createServer(common.mustCall(function(socket) { this.close(); socket.end(message); -})).listen(0, function() { +})).listen(0, common.mustCall(function() { let received = 0; const buffers = []; const sockBuf = Buffer.alloc(8); @@ -17,23 +17,23 @@ net.createServer(common.mustCall(function(socket) { port: this.address().port, onread: { buffer: sockBuf, - callback: function(nread, buf) { + callback: common.mustCallAtLeast(function(nread, buf) { assert.strictEqual(buf, sockBuf); received += nread; buffers.push(Buffer.from(buf.slice(0, nread))); - } + }) } }).on('data', common.mustNotCall()).on('end', common.mustCall(() => { assert.strictEqual(received, message.length); assert.deepStrictEqual(Buffer.concat(buffers), message); })); -}); +})); // Test Uint8Array support net.createServer(common.mustCall(function(socket) { this.close(); socket.end(message); -})).listen(0, function() { +})).listen(0, common.mustCall(function() { let received = 0; let incoming = new Uint8Array(0); const sockBuf = new Uint8Array(8); @@ -41,26 +41,26 @@ net.createServer(common.mustCall(function(socket) { port: this.address().port, onread: { buffer: sockBuf, - callback: function(nread, buf) { + callback: common.mustCallAtLeast(function(nread, buf) { assert.strictEqual(buf, sockBuf); received += nread; const newIncoming = new Uint8Array(incoming.length + nread); newIncoming.set(incoming); newIncoming.set(buf.slice(0, nread), incoming.length); incoming = newIncoming; - } + }) } }).on('data', common.mustNotCall()).on('end', common.mustCall(() => { assert.strictEqual(received, message.length); assert.deepStrictEqual(incoming, new Uint8Array(message)); })); -}); +})); // Test Buffer callback usage net.createServer(common.mustCall(function(socket) { this.close(); socket.end(message); -})).listen(0, function() { +})).listen(0, common.mustCall(function() { let received = 0; const incoming = []; const bufPool = [ Buffer.alloc(2), Buffer.alloc(2), Buffer.alloc(2) ]; @@ -74,24 +74,24 @@ net.createServer(common.mustCall(function(socket) { bufPoolIdx = (bufPoolIdx + 1) % bufPool.length; return bufPool[bufPoolIdx]; }, - callback: function(nread, buf) { + callback: common.mustCallAtLeast(function(nread, buf) { assert.strictEqual(buf, bufPool[bufPoolIdx]); received += nread; incoming.push(Buffer.from(buf.slice(0, nread))); - } + }) } }).on('data', common.mustNotCall()).on('end', common.mustCall(() => { assert.strictEqual(received, message.length); assert.deepStrictEqual(Buffer.concat(incoming), message); assert.strictEqual(bufPoolUsage, 7); })); -}); +})); // Test Uint8Array callback support net.createServer(common.mustCall(function(socket) { this.close(); socket.end(message); -})).listen(0, function() { +})).listen(0, common.mustCall(function() { let received = 0; let incoming = new Uint8Array(0); const bufPool = [ new Uint8Array(2), new Uint8Array(2), new Uint8Array(2) ]; @@ -105,27 +105,27 @@ net.createServer(common.mustCall(function(socket) { bufPoolIdx = (bufPoolIdx + 1) % bufPool.length; return bufPool[bufPoolIdx]; }, - callback: function(nread, buf) { + callback: common.mustCallAtLeast(function(nread, buf) { assert.strictEqual(buf, bufPool[bufPoolIdx]); received += nread; const newIncoming = new Uint8Array(incoming.length + nread); newIncoming.set(incoming); newIncoming.set(buf.slice(0, nread), incoming.length); incoming = newIncoming; - } + }) } }).on('data', common.mustNotCall()).on('end', common.mustCall(() => { assert.strictEqual(received, message.length); assert.deepStrictEqual(incoming, new Uint8Array(message)); assert.strictEqual(bufPoolUsage, 7); })); -}); +})); // Test explicit socket pause net.createServer(common.mustCall(function(socket) { this.close(); socket.end(message); -})).listen(0, function() { +})).listen(0, common.mustCall(function() { let received = 0; const buffers = []; const sockBuf = Buffer.alloc(8); @@ -134,7 +134,7 @@ net.createServer(common.mustCall(function(socket) { port: this.address().port, onread: { buffer: sockBuf, - callback: function(nread, buf) { + callback: common.mustCallAtLeast(function(nread, buf) { assert.strictEqual(paused, false); assert.strictEqual(buf, sockBuf); received += nread; @@ -145,19 +145,19 @@ net.createServer(common.mustCall(function(socket) { paused = false; this.resume(); }, 100); - } + }) } }).on('data', common.mustNotCall()).on('end', common.mustCall(() => { assert.strictEqual(received, message.length); assert.deepStrictEqual(Buffer.concat(buffers), message); })); -}); +})); // Test implicit socket pause net.createServer(common.mustCall(function(socket) { this.close(); socket.end(message); -})).listen(0, function() { +})).listen(0, common.mustCall(function() { let received = 0; const buffers = []; const sockBuf = Buffer.alloc(8); @@ -166,7 +166,7 @@ net.createServer(common.mustCall(function(socket) { port: this.address().port, onread: { buffer: sockBuf, - callback: function(nread, buf) { + callback: common.mustCallAtLeast(function(nread, buf) { assert.strictEqual(paused, false); assert.strictEqual(buf, sockBuf); received += nread; @@ -177,10 +177,10 @@ net.createServer(common.mustCall(function(socket) { this.resume(); }, 100); return false; - } + }) } }).on('data', common.mustNotCall()).on('end', common.mustCall(() => { assert.strictEqual(received, message.length); assert.deepStrictEqual(Buffer.concat(buffers), message); })); -}); +})); diff --git a/test/parallel/test-net-persistent-keepalive.js b/test/parallel/test-net-persistent-keepalive.js index b25162996e1bd0..8caf640a4bbedd 100644 --- a/test/parallel/test-net-persistent-keepalive.js +++ b/test/parallel/test-net-persistent-keepalive.js @@ -1,29 +1,29 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); let serverConnection; let clientConnection; -const echoServer = net.createServer(function(connection) { +const echoServer = net.createServer(common.mustCall((connection) => { serverConnection = connection; - setTimeout(function() { + setTimeout(common.mustCall(() => { // Make sure both connections are still open assert.strictEqual(serverConnection.readyState, 'open'); assert.strictEqual(clientConnection.readyState, 'open'); serverConnection.end(); clientConnection.end(); echoServer.close(); - }, 600); + }), 600); connection.setTimeout(0); assert.strictEqual(typeof connection.setKeepAlive, 'function'); connection.on('end', function() { connection.end(); }); -}); +})); echoServer.listen(0); -echoServer.on('listening', function() { +echoServer.on('listening', common.mustCall(function() { clientConnection = new net.Socket(); // Send a keepalive packet after 1000 ms // and make sure it persists @@ -31,4 +31,4 @@ echoServer.on('listening', function() { assert.ok(s instanceof net.Socket); clientConnection.connect(this.address().port); clientConnection.setTimeout(0); -}); +})); diff --git a/test/parallel/test-net-persistent-nodelay.js b/test/parallel/test-net-persistent-nodelay.js index de7f0a7f65813e..04c2e046cb76b2 100644 --- a/test/parallel/test-net-persistent-nodelay.js +++ b/test/parallel/test-net-persistent-nodelay.js @@ -1,6 +1,6 @@ // Flags: --expose-internals 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); const { internalBinding } = require('internal/test/binding'); @@ -21,7 +21,7 @@ TCPWrap.prototype.setNoDelay = function(enable) { callCount++; }; -echoServer.on('listening', function() { +echoServer.on('listening', common.mustCall(function() { const sock1 = new Socket(); // setNoDelay before the handle is created // there is probably a better way to test this @@ -29,8 +29,8 @@ echoServer.on('listening', function() { const s = sock1.setNoDelay(); assert.ok(s instanceof net.Socket); sock1.connect(this.address().port); - sock1.on('end', function() { + sock1.on('end', common.mustCall(() => { assert.strictEqual(callCount, 1); echoServer.close(); - }); -}); + })); +})); diff --git a/test/parallel/test-net-persistent-ref-unref.js b/test/parallel/test-net-persistent-ref-unref.js index 5df661475e3eee..14eff5d4b23e7e 100644 --- a/test/parallel/test-net-persistent-ref-unref.js +++ b/test/parallel/test-net-persistent-ref-unref.js @@ -1,6 +1,6 @@ // Flags: --expose-internals 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); const { internalBinding } = require('internal/test/binding'); @@ -15,27 +15,27 @@ const unref = TCPWrap.prototype.unref; let refCount = 0; -TCPWrap.prototype.ref = function() { +TCPWrap.prototype.ref = common.mustCallAtLeast(function() { ref.call(this); refCount++; assert.strictEqual(refCount, 0); -}; +}); -TCPWrap.prototype.unref = function() { +TCPWrap.prototype.unref = common.mustCallAtLeast(function() { unref.call(this); refCount--; assert.strictEqual(refCount, -1); -}; +}); echoServer.listen(0); -echoServer.on('listening', function() { +echoServer.on('listening', common.mustCall(function() { const sock = new net.Socket(); sock.unref(); sock.ref(); sock.connect(this.address().port); - sock.on('end', () => { + sock.on('end', common.mustCall(() => { assert.strictEqual(refCount, 0); echoServer.close(); - }); -}); + })); +})); diff --git a/test/parallel/test-net-pipe-with-long-path.js b/test/parallel/test-net-pipe-with-long-path.js index cebafd6028520e..e35fd4a1e0ca3e 100644 --- a/test/parallel/test-net-pipe-with-long-path.js +++ b/test/parallel/test-net-pipe-with-long-path.js @@ -19,18 +19,18 @@ const pipePath = `${tmpdir.path}/${'x'.repeat(10000)}.sock`; const server = net.createServer() .listen(pipePath) // It may work on some operating systems - .on('listening', () => { + .on('listening', common.mustCallAtLeast(() => { // The socket file must exist assert.ok(fs.existsSync(pipePath)); const socket = net.connect(pipePath, common.mustCall(() => { socket.destroy(); server.close(); })); - }) - .on('error', (error) => { + }, 0)) + .on('error', common.mustCall((error) => { assert.ok(error.code === 'EINVAL', error.message); net.connect(pipePath) .on('error', common.mustCall((error) => { assert.ok(error.code === 'EINVAL', error.message); })); - }); + })); diff --git a/test/parallel/test-net-reconnect.js b/test/parallel/test-net-reconnect.js index 233f5b01e5445a..2f7de82eb44235 100644 --- a/test/parallel/test-net-reconnect.js +++ b/test/parallel/test-net-reconnect.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); @@ -30,7 +30,7 @@ let client_recv_count = 0; let client_end_count = 0; let disconnect_count = 0; -const server = net.createServer(function(socket) { +const server = net.createServer(common.mustCallAtLeast((socket) => { console.error('SERVER: got socket connection'); socket.resume(); @@ -42,13 +42,13 @@ const server = net.createServer(function(socket) { socket.end(); }); - socket.on('close', (had_error) => { + socket.on('close', common.mustCall((had_error) => { console.log(`SERVER had_error: ${JSON.stringify(had_error)}`); assert.strictEqual(had_error, false); - }); -}); + })); +})); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { console.log('SERVER listening'); const client = net.createConnection(this.address().port); @@ -58,28 +58,28 @@ server.listen(0, function() { console.error('CLIENT connected', client._writableState); }); - client.on('data', function(chunk) { + client.on('data', common.mustCallAtLeast((chunk) => { client_recv_count += 1; console.log(`client_recv_count ${client_recv_count}`); assert.strictEqual(chunk, 'hello\r\n'); console.error('CLIENT: calling end', client._writableState); client.end(); - }); + })); client.on('end', () => { console.error('CLIENT end'); client_end_count++; }); - client.on('close', (had_error) => { + client.on('close', common.mustCallAtLeast((had_error) => { console.log('CLIENT disconnect'); assert.strictEqual(had_error, false); if (disconnect_count++ < N) client.connect(server.address().port); // reconnect else server.close(); - }); -}); + })); +})); process.on('exit', () => { assert.strictEqual(disconnect_count, N + 1); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index 615f22979c2ff9..7a35619501462e 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -43,14 +43,14 @@ const server = net.createServer(common.mustCall(function(socket) { socket.on('end', function() { if (++conns_closed === 2) server.close(); }); - socket.on('close', function() { + socket.on('close', common.mustCall(() => { assert.ok(remoteAddrCandidates.includes(socket.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily)); - }); + })); socket.resume(); }, 2)); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { const client = net.createConnection(this.address().port, '127.0.0.1'); const client2 = net.createConnection(this.address().port); @@ -61,24 +61,24 @@ server.listen(0, function() { assert.strictEqual(client2.remoteFamily, undefined); assert.strictEqual(client2.remotePort, undefined); - client.on('connect', function() { + client.on('connect', common.mustCall(() => { assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); assert.strictEqual(client.remotePort, server.address().port); client.end(); - }); - client.on('close', function() { + })); + client.on('close', common.mustCall(() => { assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); - }); - client2.on('connect', function() { + })); + client2.on('connect', common.mustCall(() => { assert.ok(remoteAddrCandidates.includes(client2.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily)); assert.strictEqual(client2.remotePort, server.address().port); client2.end(); - }); - client2.on('close', function() { + })); + client2.on('close', common.mustCall(() => { assert.ok(remoteAddrCandidates.includes(client2.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily)); - }); -}); + })); +})); diff --git a/test/parallel/test-net-remote-address.js b/test/parallel/test-net-remote-address.js index a116cb99d3bcab..904e8dcccb56c5 100644 --- a/test/parallel/test-net-remote-address.js +++ b/test/parallel/test-net-remote-address.js @@ -2,18 +2,18 @@ const common = require('../common'); const net = require('net'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const server = net.createServer(); server.listen(common.mustCall(function() { const socket = net.connect({ port: server.address().port }); - strictEqual(socket.connecting, true); - strictEqual(socket.remoteAddress, undefined); + assert.strictEqual(socket.connecting, true); + assert.strictEqual(socket.remoteAddress, undefined); socket.on('connect', common.mustCall(function() { - strictEqual(socket.remoteAddress !== undefined, true); + assert.strictEqual(socket.remoteAddress !== undefined, true); socket.end(); })); diff --git a/test/parallel/test-net-server-close.js b/test/parallel/test-net-server-close.js index 8291f70432ec97..ff08150bbf1773 100644 --- a/test/parallel/test-net-server-close.js +++ b/test/parallel/test-net-server-close.js @@ -26,7 +26,7 @@ const net = require('net'); const sockets = []; -const server = net.createServer(function(c) { +const server = net.createServer(common.mustCallAtLeast((c) => { c.on('close', common.mustCall()); sockets.push(c); @@ -35,7 +35,7 @@ const server = net.createServer(function(c) { assert.strictEqual(server.close(), server); sockets.forEach((c) => c.destroy()); } -}); +})); server.on('close', common.mustCall()); diff --git a/test/parallel/test-net-server-listen-path.js b/test/parallel/test-net-server-listen-path.js index 2be36b90252479..8c9d209b3d4afa 100644 --- a/test/parallel/test-net-server-listen-path.js +++ b/test/parallel/test-net-server-listen-path.js @@ -73,7 +73,7 @@ function randomPipePath() { // Test should emit "error" events when listening fails. { const handlePath = randomPipePath(); - const server1 = net.createServer().listen({ path: handlePath }, () => { + const server1 = net.createServer().listen({ path: handlePath }, common.mustCall(() => { // As the handlePath is in use, binding to the same address again should // make the server emit an 'EADDRINUSE' error. const server2 = net.createServer() @@ -87,5 +87,5 @@ function randomPipePath() { assert.strictEqual(err.code, 'EADDRINUSE'); assert.match(err.message, /^listen EADDRINUSE: address already in use/); })); - }); + })); } diff --git a/test/parallel/test-net-server-listen-remove-callback.js b/test/parallel/test-net-server-listen-remove-callback.js index a874099fb8c782..87bd7448aef1d8 100644 --- a/test/parallel/test-net-server-listen-remove-callback.js +++ b/test/parallel/test-net-server-listen-remove-callback.js @@ -20,18 +20,18 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); // Server should only fire listen callback once const server = net.createServer(); -server.on('close', function() { +server.on('close', common.mustCall(() => { const listeners = server.listeners('listening'); console.log('Closed, listeners:', listeners.length); assert.strictEqual(listeners.length, 0); -}); +}, 2)); server.listen(0, function() { server.close(); diff --git a/test/parallel/test-net-server-max-connections-close-makes-more-available.js b/test/parallel/test-net-server-max-connections-close-makes-more-available.js index f607f28c10eaa2..c889e41265e9fe 100644 --- a/test/parallel/test-net-server-max-connections-close-makes-more-available.js +++ b/test/parallel/test-net-server-max-connections-close-makes-more-available.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); @@ -28,10 +28,10 @@ function createConnection(index) { sent.push(msg); }); - connection.on('error', function(err) { + connection.on('error', common.mustCallAtLeast((err) => { assert.strictEqual(err.code, 'ECONNRESET'); resolve(); - }); + }, 0)); connection.on('data', function(e) { console.error(`connection ${index} received response`); diff --git a/test/parallel/test-net-server-max-connections.js b/test/parallel/test-net-server-max-connections.js index ea9a8d29e9f1ed..4e347de7892c34 100644 --- a/test/parallel/test-net-server-max-connections.js +++ b/test/parallel/test-net-server-max-connections.js @@ -49,12 +49,12 @@ function makeConnection(index) { const c = net.createConnection(server.address().port); let gotData = false; - c.on('connect', function() { + c.on('connect', common.mustCall(() => { if (index + 1 < N) { makeConnection(index + 1); } - c.on('close', function() { + c.on('close', common.mustCall(() => { console.error(`closed ${index}`); closes++; @@ -81,15 +81,15 @@ function makeConnection(index) { assert.strictEqual(gotData, false, `${index} got data, but shouldn't have`); } - }); - }); + })); + })); c.on('end', function() { c.end(); }); - c.on('data', function(b) { + c.on('data', common.mustCallAtLeast((b) => { gotData = true; assert.ok(b.length > 0); - }); + }, 0)); c.on('error', function(e) { // Retry if SmartOS and ECONNREFUSED. See diff --git a/test/parallel/test-net-server-pause-on-connect.js b/test/parallel/test-net-server-pause-on-connect.js index 59c39e8816cc5c..51bdec9ac6411a 100644 --- a/test/parallel/test-net-server-pause-on-connect.js +++ b/test/parallel/test-net-server-pause-on-connect.js @@ -28,8 +28,8 @@ let stopped = true; let server1Sock; -const server1ConnHandler = (socket) => { - socket.on('data', function(data) { +const server1ConnHandler = common.mustCall((socket) => { + socket.on('data', common.mustCall((data) => { if (stopped) { assert.fail('data event should not have happened yet'); } @@ -37,15 +37,15 @@ const server1ConnHandler = (socket) => { assert.strictEqual(data.toString(), msg); socket.end(); server1.close(); - }); + })); server1Sock = socket; -}; +}); const server1 = net.createServer({ pauseOnConnect: true }, server1ConnHandler); -const server2ConnHandler = (socket) => { - socket.on('data', function(data) { +const server2ConnHandler = common.mustCall((socket) => { + socket.on('data', common.mustCall((data) => { assert.strictEqual(data.toString(), msg); socket.end(); server2.close(); @@ -53,19 +53,19 @@ const server2ConnHandler = (socket) => { assert.strictEqual(server1Sock.bytesRead, 0); server1Sock.resume(); stopped = false; - }); -}; + })); +}); const server2 = net.createServer({ pauseOnConnect: false }, server2ConnHandler); -server1.listen(0, function() { +server1.listen(0, common.mustCall(function() { const clientHandler = common.mustCall(function() { server2.listen(0, function() { net.createConnection({ port: this.address().port }).write(msg); }); }); net.createConnection({ port: this.address().port }).write(msg, clientHandler); -}); +})); process.on('exit', function() { assert.strictEqual(stopped, false); diff --git a/test/parallel/test-net-server-reset.js b/test/parallel/test-net-server-reset.js index 3f9c049f3c3c36..9e6e9c45fd40b1 100644 --- a/test/parallel/test-net-server-reset.js +++ b/test/parallel/test-net-server-reset.js @@ -5,7 +5,7 @@ const net = require('net'); const sockets = []; -const server = net.createServer(function(c) { +const server = net.createServer(common.mustCallAtLeast((c) => { c.on('close', common.mustCall()); sockets.push(c); @@ -14,11 +14,11 @@ const server = net.createServer(function(c) { assert.strictEqual(server.close(), server); sockets.forEach((c) => c.resetAndDestroy()); } -}); +})); server.on('close', common.mustCall()); -assert.strictEqual(server, server.listen(0, () => { +assert.strictEqual(server, server.listen(0, common.mustCall(() => { net.createConnection(server.address().port) .on('error', common.mustCall((error) => { assert.strictEqual(error.code, 'ECONNRESET'); @@ -27,4 +27,4 @@ assert.strictEqual(server, server.listen(0, () => { .on('error', common.mustCall((error) => { assert.strictEqual(error.code, 'ECONNRESET'); })); -})); +}))); diff --git a/test/parallel/test-net-settimeout.js b/test/parallel/test-net-settimeout.js index 581e27ec327d62..5662a5cc41400f 100644 --- a/test/parallel/test-net-settimeout.js +++ b/test/parallel/test-net-settimeout.js @@ -33,7 +33,7 @@ const server = net.createServer(common.mustCall((c) => { c.write('hello'); })); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { const socket = net.createConnection(this.address().port, 'localhost'); const s = socket.setTimeout(T, common.mustNotCall()); @@ -47,4 +47,4 @@ server.listen(0, function() { })); socket.setTimeout(0); -}); +})); diff --git a/test/parallel/test-net-socket-close-after-end.js b/test/parallel/test-net-socket-close-after-end.js index 06bf55f89d6e50..4b86849c1e83e5 100644 --- a/test/parallel/test-net-socket-close-after-end.js +++ b/test/parallel/test-net-socket-close-after-end.js @@ -6,7 +6,7 @@ const net = require('net'); const server = net.createServer(); -server.on('connection', (socket) => { +server.on('connection', common.mustCall((socket) => { let endEmitted = false; socket.once('readable', () => { @@ -17,12 +17,12 @@ server.on('connection', (socket) => { socket.on('end', () => { endEmitted = true; }); - socket.on('close', () => { + socket.on('close', common.mustCall(() => { assert(endEmitted); server.close(); - }); + })); socket.end('foo'); -}); +})); server.listen(common.mustCall(() => { const socket = net.createConnection(server.address().port, () => { diff --git a/test/parallel/test-net-socket-connecting.js b/test/parallel/test-net-socket-connecting.js index 21aa261192c17d..222361a8843eb9 100644 --- a/test/parallel/test-net-socket-connecting.js +++ b/test/parallel/test-net-socket-connecting.js @@ -1,21 +1,21 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); const server = net.createServer((conn) => { conn.end(); server.close(); -}).listen(0, () => { - const client = net.connect(server.address().port, () => { +}).listen(0, common.mustCall(() => { + const client = net.connect(server.address().port, common.mustCall(() => { assert.strictEqual(client.connecting, false); // Legacy getter assert.strictEqual(client._connecting, false); client.end(); - }); + })); assert.strictEqual(client.connecting, true); // Legacy getter assert.strictEqual(client._connecting, true); -}); +})); diff --git a/test/parallel/test-net-socket-no-halfopen-enforcer.js b/test/parallel/test-net-socket-no-halfopen-enforcer.js index 3df5b6d7b9c8cb..69ebd694e8fa76 100644 --- a/test/parallel/test-net-socket-no-halfopen-enforcer.js +++ b/test/parallel/test-net-socket-no-halfopen-enforcer.js @@ -5,7 +5,7 @@ require('../common'); // enforcer from `stream.Duplex`. const { Socket } = require('net'); -const { strictEqual } = require('assert'); +const assert = require('assert'); const socket = new Socket({ allowHalfOpen: false }); -strictEqual(socket.listenerCount('end'), 1); +assert.strictEqual(socket.listenerCount('end'), 1); diff --git a/test/parallel/test-net-socket-setnodelay.js b/test/parallel/test-net-socket-setnodelay.js index 0be94a7ba461ee..97cf992b162eae 100644 --- a/test/parallel/test-net-socket-setnodelay.js +++ b/test/parallel/test-net-socket-setnodelay.js @@ -6,14 +6,14 @@ const net = require('net'); const truthyValues = [true, 1, 'true', {}, []]; const falseyValues = [false, 0, '']; -const genSetNoDelay = (desiredArg) => (enable) => { +const genSetNoDelay = common.mustCall((desiredArg) => common.mustCall((enable) => { assert.strictEqual(enable, desiredArg); -}; +}), 2); // setNoDelay should default to true let socket = new net.Socket({ handle: { - setNoDelay: common.mustCall(genSetNoDelay(true)), + setNoDelay: genSetNoDelay(true), readStart() {} } }); @@ -21,7 +21,7 @@ socket.setNoDelay(); socket = new net.Socket({ handle: { - setNoDelay: common.mustCall(genSetNoDelay(true), 1), + setNoDelay: genSetNoDelay(true), readStart() {} } }); diff --git a/test/parallel/test-net-socket-write-error.js b/test/parallel/test-net-socket-write-error.js index e68db68c0d4939..c181c9ce90116e 100644 --- a/test/parallel/test-net-socket-write-error.js +++ b/test/parallel/test-net-socket-write-error.js @@ -7,7 +7,7 @@ const assert = require('assert'); const server = net.createServer().listen(0, connectToServer); function connectToServer() { - const client = net.createConnection(this.address().port, () => { + const client = net.createConnection(this.address().port, common.mustCall(() => { client.on('error', common.mustNotCall()); assert.throws(() => { client.write(1337); @@ -17,6 +17,6 @@ function connectToServer() { }); client.destroy(); - }) + })) .on('close', () => server.close()); } diff --git a/test/parallel/test-net-stream.js b/test/parallel/test-net-stream.js index 454dc69038aa48..cf6d615591ea75 100644 --- a/test/parallel/test-net-stream.js +++ b/test/parallel/test-net-stream.js @@ -29,7 +29,7 @@ const SIZE = 2E6; const N = 10; const buf = Buffer.alloc(SIZE, 'a'); -const server = net.createServer(function(socket) { +const server = net.createServer(common.mustCall((socket) => { socket.setNoDelay(); socket.on('error', common.mustCall(() => socket.destroy())) @@ -40,12 +40,12 @@ const server = net.createServer(function(socket) { } socket.end(); -}).listen(0, function() { +})).listen(0, common.mustCall(function() { const conn = net.connect(this.address().port); - conn.on('data', function(buf) { + conn.on('data', common.mustCall((buf) => { assert.strictEqual(conn, conn.pause()); setTimeout(function() { conn.destroy(); }, 20); - }); -}); + })); +})); diff --git a/test/parallel/test-net-sync-cork.js b/test/parallel/test-net-sync-cork.js index 447f42ca91e768..49f68960ce6390 100644 --- a/test/parallel/test-net-sync-cork.js +++ b/test/parallel/test-net-sync-cork.js @@ -9,10 +9,10 @@ const server = net.createServer(handle); const N = 100; const buf = Buffer.alloc(2, 'a'); -server.listen(0, function() { +server.listen(0, common.mustCall(function() { const conn = net.connect(this.address().port); - conn.on('connect', () => { + conn.on('connect', common.mustCall(() => { let res = true; let i = 0; for (; i < N && res; i++) { @@ -23,8 +23,8 @@ server.listen(0, function() { } assert.strictEqual(i, N); conn.end(); - }); -}); + })); +})); function handle(socket) { socket.resume(); diff --git a/test/parallel/test-net-throttle.js b/test/parallel/test-net-throttle.js index fd9e2be9aece41..c9128ff85714b2 100644 --- a/test/parallel/test-net-throttle.js +++ b/test/parallel/test-net-throttle.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const net = require('net'); const debuglog = require('util').debuglog('test'); @@ -29,7 +29,7 @@ let chars_recved = 0; let npauses = 0; let totalLength = 0; -const server = net.createServer((connection) => { +const server = net.createServer(common.mustCallAtLeast((connection) => { const body = 'C'.repeat(1024); let n = 1; debuglog('starting write loop'); @@ -49,15 +49,15 @@ const server = net.createServer((connection) => { `writableLength: ${connection.writableLength}, totalLength: ${totalLength}`, ); connection.end(); -}); +})); -server.listen(0, () => { +server.listen(0, common.mustCall(() => { const port = server.address().port; debuglog(`server started on port ${port}`); let paused = false; const client = net.createConnection(port); client.setEncoding('ascii'); - client.on('data', (d) => { + client.on('data', common.mustCallAtLeast((d) => { chars_recved += d.length; debuglog(`got ${chars_recved}`); if (!paused) { @@ -66,20 +66,20 @@ server.listen(0, () => { paused = true; debuglog('pause'); const x = chars_recved; - setTimeout(() => { + setTimeout(common.mustCall(() => { assert.strictEqual(chars_recved, x); client.resume(); debuglog('resume'); paused = false; - }, 100); + }), 100); } - }); + })); client.on('end', () => { server.close(); client.end(); }); -}); +})); process.on('exit', () => { diff --git a/test/parallel/test-net-write-after-close.js b/test/parallel/test-net-write-after-close.js index 2647e3d0d97095..9f259935f491f1 100644 --- a/test/parallel/test-net-write-after-close.js +++ b/test/parallel/test-net-write-after-close.js @@ -35,8 +35,8 @@ const server = net.createServer(common.mustCall(function(socket) { socket.on('error', common.mustNotCall()); })); -server.listen(0, function() { - const client = net.connect(this.address().port, function() { +server.listen(0, common.mustCall(function() { + const client = net.connect(this.address().port, common.mustCall(() => { // client.end() will close both the readable and writable side // of the duplex because allowHalfOpen defaults to false. // Then 'end' will be emitted when it receives a FIN packet from @@ -48,5 +48,5 @@ server.listen(0, function() { })); })); client.end(); - }); -}); + })); +})); diff --git a/test/parallel/test-net-write-after-end-nt.js b/test/parallel/test-net-write-after-end-nt.js index 99edc1d72beb95..bcb986c2249683 100644 --- a/test/parallel/test-net-write-after-end-nt.js +++ b/test/parallel/test-net-write-after-end-nt.js @@ -10,8 +10,8 @@ const { expectsError, mustCall } = common; // after sockets ending will be emitted in the next tick. const server = net.createServer(mustCall((socket) => { socket.end(); -})).listen(() => { - const client = net.connect(server.address().port, () => { +})).listen(mustCall(() => { + const client = net.connect(server.address().port, mustCall(() => { let hasError = false; client.on('error', mustCall((err) => { hasError = true; @@ -28,5 +28,5 @@ const server = net.createServer(mustCall((socket) => { assert(!hasError, 'The error should be emitted in the next tick.'); })); client.end(); - }); -}); + })); +})); diff --git a/test/parallel/test-next-tick-errors.js b/test/parallel/test-next-tick-errors.js index 6fd079625afae2..28df53c8bfc2fd 100644 --- a/test/parallel/test-next-tick-errors.js +++ b/test/parallel/test-next-tick-errors.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const order = []; @@ -57,7 +57,7 @@ testNextTickWith('str'); testNextTickWith({}); testNextTickWith([]); -process.on('uncaughtException', function(err, errorOrigin) { +process.on('uncaughtException', common.mustCall((err, errorOrigin) => { assert.strictEqual(errorOrigin, 'uncaughtException'); if (!exceptionHandled) { @@ -67,7 +67,7 @@ process.on('uncaughtException', function(err, errorOrigin) { // If we get here then the first process.nextTick got called twice order.push('OOPS!'); } -}); +})); process.on('exit', function() { assert.deepStrictEqual(order, ['A', 'B', 'C']); diff --git a/test/parallel/test-nodeeventtarget.js b/test/parallel/test-nodeeventtarget.js index 6643584a6fc1d0..3803e29fc4bee1 100644 --- a/test/parallel/test-nodeeventtarget.js +++ b/test/parallel/test-nodeeventtarget.js @@ -4,102 +4,97 @@ const common = require('../common'); const { NodeEventTarget } = require('internal/event_target'); -const { - deepStrictEqual, - ok, - strictEqual, - throws, -} = require('assert'); +const assert = require('assert'); const { on } = require('events'); { const eventTarget = new NodeEventTarget(); - strictEqual(eventTarget.listenerCount('foo'), 0); - deepStrictEqual(eventTarget.eventNames(), []); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); + assert.deepStrictEqual(eventTarget.eventNames(), []); const ev1 = common.mustCall(function(event) { - strictEqual(event.type, 'foo'); - strictEqual(this, eventTarget); + assert.strictEqual(event.type, 'foo'); + assert.strictEqual(this, eventTarget); }, 2); const ev2 = { handleEvent: common.mustCall(function(event) { - strictEqual(event.type, 'foo'); - strictEqual(this, ev2); + assert.strictEqual(event.type, 'foo'); + assert.strictEqual(this, ev2); }) }; eventTarget.addEventListener('foo', ev1); eventTarget.addEventListener('foo', ev2, { once: true }); - strictEqual(eventTarget.listenerCount('foo'), 2); - ok(eventTarget.dispatchEvent(new Event('foo'))); - strictEqual(eventTarget.listenerCount('foo'), 1); + assert.strictEqual(eventTarget.listenerCount('foo'), 2); + assert.ok(eventTarget.dispatchEvent(new Event('foo'))); + assert.strictEqual(eventTarget.listenerCount('foo'), 1); eventTarget.dispatchEvent(new Event('foo')); eventTarget.removeEventListener('foo', ev1); - strictEqual(eventTarget.listenerCount('foo'), 0); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); eventTarget.dispatchEvent(new Event('foo')); } { const eventTarget = new NodeEventTarget(); - strictEqual(eventTarget.listenerCount('foo'), 0); - deepStrictEqual(eventTarget.eventNames(), []); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); + assert.deepStrictEqual(eventTarget.eventNames(), []); const ev1 = common.mustCall((event) => { - strictEqual(event.type, 'foo'); + assert.strictEqual(event.type, 'foo'); }, 2); const ev2 = { handleEvent: common.mustCall((event) => { - strictEqual(event.type, 'foo'); + assert.strictEqual(event.type, 'foo'); }) }; - strictEqual(eventTarget.on('foo', ev1), eventTarget); - strictEqual(eventTarget.once('foo', ev2, { once: true }), eventTarget); - strictEqual(eventTarget.listenerCount('foo'), 2); + assert.strictEqual(eventTarget.on('foo', ev1), eventTarget); + assert.strictEqual(eventTarget.once('foo', ev2, { once: true }), eventTarget); + assert.strictEqual(eventTarget.listenerCount('foo'), 2); eventTarget.dispatchEvent(new Event('foo')); - strictEqual(eventTarget.listenerCount('foo'), 1); + assert.strictEqual(eventTarget.listenerCount('foo'), 1); eventTarget.dispatchEvent(new Event('foo')); - strictEqual(eventTarget.off('foo', ev1), eventTarget); - strictEqual(eventTarget.listenerCount('foo'), 0); + assert.strictEqual(eventTarget.off('foo', ev1), eventTarget); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); eventTarget.dispatchEvent(new Event('foo')); } { const eventTarget = new NodeEventTarget(); - strictEqual(eventTarget.listenerCount('foo'), 0); - deepStrictEqual(eventTarget.eventNames(), []); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); + assert.deepStrictEqual(eventTarget.eventNames(), []); const ev1 = common.mustCall((event) => { - strictEqual(event.type, 'foo'); + assert.strictEqual(event.type, 'foo'); }, 2); const ev2 = { handleEvent: common.mustCall((event) => { - strictEqual(event.type, 'foo'); + assert.strictEqual(event.type, 'foo'); }) }; eventTarget.addListener('foo', ev1); eventTarget.once('foo', ev2, { once: true }); - strictEqual(eventTarget.listenerCount('foo'), 2); + assert.strictEqual(eventTarget.listenerCount('foo'), 2); eventTarget.dispatchEvent(new Event('foo')); - strictEqual(eventTarget.listenerCount('foo'), 1); + assert.strictEqual(eventTarget.listenerCount('foo'), 1); eventTarget.dispatchEvent(new Event('foo')); eventTarget.removeListener('foo', ev1); - strictEqual(eventTarget.listenerCount('foo'), 0); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); eventTarget.dispatchEvent(new Event('foo')); } { const eventTarget = new NodeEventTarget(); - strictEqual(eventTarget.listenerCount('foo'), 0); - deepStrictEqual(eventTarget.eventNames(), []); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); + assert.deepStrictEqual(eventTarget.eventNames(), []); // Won't actually be called. const ev1 = () => {}; @@ -112,33 +107,33 @@ const { on } = require('events'); eventTarget.once('foo', ev2, { once: true }); eventTarget.once('foo', ev2, { once: false }); eventTarget.on('bar', ev1); - strictEqual(eventTarget.listenerCount('foo'), 2); - strictEqual(eventTarget.listenerCount('bar'), 1); - deepStrictEqual(eventTarget.eventNames(), ['foo', 'bar']); - strictEqual(eventTarget.removeAllListeners('foo'), eventTarget); - strictEqual(eventTarget.listenerCount('foo'), 0); - strictEqual(eventTarget.listenerCount('bar'), 1); - deepStrictEqual(eventTarget.eventNames(), ['bar']); - strictEqual(eventTarget.removeAllListeners(), eventTarget); - strictEqual(eventTarget.listenerCount('foo'), 0); - strictEqual(eventTarget.listenerCount('bar'), 0); - deepStrictEqual(eventTarget.eventNames(), []); + assert.strictEqual(eventTarget.listenerCount('foo'), 2); + assert.strictEqual(eventTarget.listenerCount('bar'), 1); + assert.deepStrictEqual(eventTarget.eventNames(), ['foo', 'bar']); + assert.strictEqual(eventTarget.removeAllListeners('foo'), eventTarget); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); + assert.strictEqual(eventTarget.listenerCount('bar'), 1); + assert.deepStrictEqual(eventTarget.eventNames(), ['bar']); + assert.strictEqual(eventTarget.removeAllListeners(), eventTarget); + assert.strictEqual(eventTarget.listenerCount('foo'), 0); + assert.strictEqual(eventTarget.listenerCount('bar'), 0); + assert.deepStrictEqual(eventTarget.eventNames(), []); } { const target = new NodeEventTarget(); process.on('warning', common.mustCall((warning) => { - ok(warning instanceof Error); - strictEqual(warning.name, 'MaxListenersExceededWarning'); - strictEqual(warning.target, target); - strictEqual(warning.count, 2); - strictEqual(warning.type, 'foo'); - ok(warning.message.includes( + assert.ok(warning instanceof Error); + assert.strictEqual(warning.name, 'MaxListenersExceededWarning'); + assert.strictEqual(warning.target, target); + assert.strictEqual(warning.count, 2); + assert.strictEqual(warning.type, 'foo'); + assert.ok(warning.message.includes( '2 foo listeners added to NodeEventTarget')); })); - strictEqual(target.getMaxListeners(), NodeEventTarget.defaultMaxListeners); + assert.strictEqual(target.getMaxListeners(), NodeEventTarget.defaultMaxListeners); target.setMaxListeners(1); target.on('foo', () => {}); target.on('foo', () => {}); @@ -147,20 +142,20 @@ const { on } = require('events'); // Test NodeEventTarget emit const emitter = new NodeEventTarget(); emitter.addEventListener('foo', common.mustCall((e) => { - strictEqual(e.type, 'foo'); - strictEqual(e.detail, 'bar'); - ok(e instanceof Event); + assert.strictEqual(e.type, 'foo'); + assert.strictEqual(e.detail, 'bar'); + assert.ok(e instanceof Event); }), { once: true }); emitter.once('foo', common.mustCall((e, droppedAdditionalArgument) => { - strictEqual(e, 'bar'); - strictEqual(droppedAdditionalArgument, undefined); + assert.strictEqual(e, 'bar'); + assert.strictEqual(droppedAdditionalArgument, undefined); })); emitter.emit('foo', 'bar', 'baz'); } { // Test NodeEventTarget emit unsupported usage const emitter = new NodeEventTarget(); - throws(() => { + assert.throws(() => { emitter.emit(); }, /ERR_INVALID_ARG_TYPE/); } @@ -174,7 +169,7 @@ const { on } = require('events'); let count = 0; for await (const [ item ] of on(emitter, 'foo')) { count++; - strictEqual(item.type, 'foo'); + assert.strictEqual(item.type, 'foo'); if (count > 5) { break; }