8000 test: ensure assertions are reached on more tests · nodejs/node@47ed959 · GitHub
[go: up one dir, main page]

Skip to content

Commit 47ed959

Browse files
aduh95RafaelGSS
authored andcommitted
test: ensure assertions are reached on more tests
PR-URL: #60761 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 79d48f9 commit 47ed959
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    49 files changed

    +276
    -285
    lines changed

    test/eslint.config_partial.mjs

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -195,7 +195,7 @@ export default [
    195195
    `test/parallel/test-{${
    196196
    // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
    197197
    Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
    198-
    },${
    198+
    },n*,${
    199199
    // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
    200200
    Array.from({ length: 5 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
    201201
    }}.{js,mjs,cjs}`,

    test/parallel/test-navigator.js

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -36,10 +36,10 @@ const { getNavigatorPlatform } = require('internal/navigator');
    3636
    const { execFile } = require('child_process');
    3737

    3838
    const is = {
    39-
    number: (value, key) => {
    39+
    number: common.mustCallAtLeast((value, key) => {
    4040
    assert(!Number.isNaN(value), `${key} should not be NaN`);
    4141
    assert.strictEqual(typeof value, 'number');
    42-
    },
    42+
    }),
    4343
    };
    4444

    4545
    is.number(+navigator.hardwareConcurrency, 'hardwareConcurrency');

    test/parallel/test-net-autoselectfamily-commandline-option.js

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,12 +10,12 @@ const { createConnection, createServer } = require('net');
    1010

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

    2020
    ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
    2121
    const port = ipv4Server.address().port;

    test/parallel/test-net-autoselectfamily-default.js

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,12 +10,12 @@ const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTime
    1010

    1111
    // Test that IPV4 is reached by default if IPV6 is not reachable and the default is enabled
    1212
    {
    13-
    const ipv4Server = createServer((socket) => {
    13+
    const ipv4Server = createServer(common.mustCall((socket) => {
    1414
    socket.on('data', common.mustCall(() => {
    1515
    socket.write('response-ipv4');
    1616
    socket.end();
    1717
    }));
    18-
    });
    18+
    }));
    1919

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

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

    5555
    ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
    5656
    setDefaultAutoSelectFamily(false);

    test/parallel/test-net-autoselectfamily-ipv4first.js

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,12 +8,12 @@ const { createConnection, createServer } = require('net');
    88

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

    1818
    const ipv6Server = createServer((socket) => {
    1919
    socket.on('data', common.mustNotCall(() => {

    test/parallel/test-net-autoselectfamily.js

    Lines changed: 8 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -16,12 +16,12 @@ const autoSelectFamilyAttemptTimeout = common.defaultAutoSelectFamilyAttemptTime
    1616

    1717
    // Test that IPV4 is reached if IPV6 is not reachable
    1818
    {
    19-
    const ipv4Server = createServer((socket) => {
    19+
    const ipv4Server = createServer(common.mustCall((socket) => {
    2020
    socket.on('data', common.mustCall(() => {
    2121
    socket.write('response-ipv4');
    2222
    socket.end();
    2323
    }));
    24-
    });
    24+
    }));
    2525

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

    5757
    // Test that only the last successful connection is established.
    5858
    {
    59-
    const ipv4Server = createServer((socket) => {
    59+
    const ipv4Server = createServer(common.mustCall((socket) => {
    6060
    socket.on('data', common.mustCall(() => {
    6161
    socket.write('response-ipv4');
    6262
    socket.end();
    6363
    }));
    64-
    });
    64+
    }));
    6565

    6666
    ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
    6767
    const port = ipv4Server.address().port;
    @@ -116,12 +116,12 @@ if (common.hasIPv6) {
    116116
    }));
    117117
    });
    118118

    119-
    const ipv6Server = createServer((socket) => {
    119+
    const ipv6Server = createServer(common.mustCall((socket) => {
    120120
    socket.on('data', common.mustCall(() => {
    121121
    socket.write('response-ipv6');
    122122
    socket.end();
    123123
    }));
    124-
    });
    124+
    }));
    125125

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

    185185
    // Test that the option can be disabled
    186186
    {
    187-
    const ipv4Server = createServer((socket) => {
    187+
    const ipv4Server = createServer(common.mustCallAtLeast((socket) => {
    188188
    socket.on('data', common.mustCall(() => {
    189189
    socket.write('response-ipv4');
    190190
    socket.end();
    191191
    }));
    192-
    });
    192+
    }, 0));
    193193

    194194
    ipv4Server.listen(0, '127.0.0.1', common.mustCall(() => {
    195195
    const port = ipv4Server.address().port;

    test/parallel/test-net-child-process-connect-reset.js

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -35,10 +35,10 @@ if (process.argv[2] === 'child') {
    3535
    }
    3636
    });
    3737

    38-
    conn.on('error', (err) => {
    38+
    conn.on('error', common.mustCallAtLeast((err) => {
    3939
    // Error emitted on Windows.
    4040
    assert.strictEqual(err.code, 'ECONNRESET');
    41-
    });
    41+
    }, 0));
    4242

    4343
    conn.on('connect', common.mustCall(() => {
    4444
    cp.kill('SIGKILL');

    test/parallel/test-net-connect-abort-controller.js

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,14 +18,14 @@ server.listen(0, common.mustCall(async () => {
    1818
    });
    1919
    });
    2020

    21-
    const assertAbort = async (socket, testName) => {
    21+
    const assertAbort = common.mustCallAtLeast(async (socket, testName) => {
    2222
    try {
    2323
    await once(socket, 'close');
    2424
    assert.fail(`close ${testName} should have thrown`);
    2525
    } catch (err) {
    2626
    assert.strictEqual(err.name, 'AbortError');
    2727
    }
    28-
    };
    28+
    });
    2929

    3030
    async function postAbort() {
    3131
    const ac = new AbortController();

    test/parallel/test-net-connect-keepalive.js

    Lines changed: 4 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,11 +8,6 @@ const truthyValues = [true, 1, 'true', {}, []];
    88
    const delays = [[123, 0], [456123, 456], [-123000, 0], [undefined, 0]];
    99
    const falseyValues = [false, 0, ''];
    1010

    11-
    const genSetKeepAlive = (desiredEnable, desiredDelay) => (enable, delay) => {
    12-
    assert.strictEqual(enable, desiredEnable);
    13-
    assert.strictEqual(delay, desiredDelay);
    14-
    };
    15-
    1611
    for (const value of truthyValues) {
    1712
    for (const delay of delays) {
    1813
    const server = net.createServer();
    @@ -26,7 +21,10 @@ for (const value of truthyValues) {
    2621
    );
    2722

    2823
    client._handle.setKeepAlive = common.mustCall(
    29-
    genSetKeepAlive(true, delay[1])
    24+
    (enable, actualDelay) => {
    25+
    assert.strictEqual(enable, true);
    26+
    assert.strictEqual(actualDelay, delay[1]);
    27+
    },
    3028
    );
    3129

    3230
    client.on('end', common.mustCall(function() {

    test/parallel/test-net-connect-memleak.js

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -50,9 +50,9 @@ const gcListener = { ongc() { collected = true; } };
    5050

    5151
    function done(sock) {
    5252
    globalThis.gc();
    53-
    setImmediate(() => {
    53+
    setImmediate(common.mustCall(() => {
    5454
    assert.strictEqual(collected, true);
    5555
    sock.end();
    5656
    server.close();
    57-
    });
    57+
    }));
    5858
    }

    0 commit comments

    Comments
     (0)
    0