Skip to content
Open
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
4 changes: 2 additions & 2 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export default [
].join(',')}}/**/*.{js,mjs,cjs}`,
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},http-*,http2-*,${
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 7 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
}}.{js,mjs,cjs}`,
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-h2leak-destroy-session-on-socket-ended.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ function client() {
rejectUnauthorized: false,
ALPNProtocols: ['h2']
}, () => {
client.end(Buffer.concat(h2fstStream.map((s) => Buffer.from(s, 'base64'))), (err) => {
assert.ifError(err);
});
client.end(Buffer.concat(h2fstStream.map((s) => Buffer.from(s, 'base64'))), common.mustSucceed());
});

client.on('error', (error) => {
Expand Down
87 changes: 32 additions & 55 deletions test/parallel/test-handle-wrap-hasref.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
'use strict';

const common = require('../common');
const strictEqual = require('assert').strictEqual;
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');

// child_process
{
const spawn = require('child_process').spawn;
const cmd = common.isWindows ? 'rundll32' : 'ls';
const cp = spawn(cmd);
strictEqual(cp._handle.hasRef(),
true, 'process_wrap: not initially refed');
assert.strictEqual(cp._handle.hasRef(), true);
cp.unref();
strictEqual(cp._handle.hasRef(),
false, 'process_wrap: unref() ineffective');
assert.strictEqual(cp._handle.hasRef(), false);
cp.ref();
strictEqual(cp._handle.hasRef(),
true, 'process_wrap: ref() ineffective');
assert.strictEqual(cp._handle.hasRef(), true);
cp._handle.close(common.mustCall(() =>
strictEqual(cp._handle.hasRef(),
false, 'process_wrap: not unrefed on close')));
assert.strictEqual(cp._handle.hasRef(), false)));
}


Expand All @@ -32,17 +28,13 @@ const { kStateSymbol } = require('internal/dgram');
const sock4 = dgram.createSocket('udp4');
const handle = sock4[kStateSymbol].handle;

strictEqual(handle.hasRef(),
true, 'udp_wrap: ipv4: not initially refed');
assert.strictEqual(handle.hasRef(), true);
sock4.unref();
strictEqual(handle.hasRef(),
false, 'udp_wrap: ipv4: unref() ineffective');
assert.strictEqual(handle.hasRef(), false);
sock4.ref();
strictEqual(handle.hasRef(),
true, 'udp_wrap: ipv4: ref() ineffective');
assert.strictEqual(handle.hasRef(), true);
handle.close(common.mustCall(() =>
strictEqual(handle.hasRef(),
false, 'udp_wrap: ipv4: not unrefed on close')));
assert.strictEqual(handle.hasRef(), false)));
}


Expand All @@ -51,85 +43,70 @@ const { kStateSymbol } = require('internal/dgram');
const sock6 = dgram.createSocket('udp6');
const handle = sock6[kStateSymbol].handle;

strictEqual(handle.hasRef(),
true, 'udp_wrap: ipv6: not initially refed');
assert.strictEqual(handle.hasRef(), true);
sock6.unref();
strictEqual(handle.hasRef(),
false, 'udp_wrap: ipv6: unref() ineffective');
assert.strictEqual(handle.hasRef(), false);
sock6.ref();
strictEqual(handle.hasRef(),
true, 'udp_wrap: ipv6: ref() ineffective');
assert.strictEqual(handle.hasRef(), true);
handle.close(common.mustCall(() =>
strictEqual(handle.hasRef(),
false, 'udp_wrap: ipv6: not unrefed on close')));
assert.strictEqual(handle.hasRef(), false)));
}


// pipe
{
const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
const handle = new Pipe(PipeConstants.SOCKET);
strictEqual(handle.hasRef(),
true, 'pipe_wrap: not initially refed');
assert.strictEqual(handle.hasRef(), true);
handle.unref();
strictEqual(handle.hasRef(),
false, 'pipe_wrap: unref() ineffective');
assert.strictEqual(handle.hasRef(), false);
handle.ref();
strictEqual(handle.hasRef(),
true, 'pipe_wrap: ref() ineffective');
assert.strictEqual(handle.hasRef(), true);
handle.close(common.mustCall(() =>
strictEqual(handle.hasRef(),
false, 'pipe_wrap: not unrefed on close')));
assert.strictEqual(handle.hasRef(), false)));
}


// tcp
{
const net = require('net');
const server = net.createServer(() => {}).listen(0);
strictEqual(server._handle.hasRef(),
true, 'tcp_wrap: not initially refed');
strictEqual(server._unref,
false, 'tcp_wrap: _unref initially incorrect');
assert.strictEqual(server._handle.hasRef(), true);
assert.strictEqual(server._unref, false);
server.unref();
strictEqual(server._handle.hasRef(),
false, 'tcp_wrap: unref() ineffective');
strictEqual(server._unref,
true, 'tcp_wrap: _unref not updated on unref()');
assert.strictEqual(server._handle.hasRef(), false);
assert.strictEqual(server._unref, true);
server.ref();
strictEqual(server._handle.hasRef(),
true, 'tcp_wrap: ref() ineffective');
strictEqual(server._unref,
false, 'tcp_wrap: _unref not updated on ref()');
assert.strictEqual(server._handle.hasRef(), true);
assert.strictEqual(server._unref, false);
server._handle.close(common.mustCall(() =>
strictEqual(server._handle.hasRef(),
false, 'tcp_wrap: not unrefed on close')));
assert.strictEqual(server._handle.hasRef(), false)));
}

// timers
{
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 0);
const timeout = setTimeout(() => {}, 500);
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 1);
timeout.unref();
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 0);
timeout.ref();
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 1);

strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 0);
const immediate = setImmediate(() => {});
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 1);
immediate.unref();
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 0);
immediate.ref();
strictEqual(process.getActiveResourcesInfo().filter(
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 1);
}

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-heapdump-async-hooks-init-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ async_hooks.createHook({
if (promiseIds.includes(id)) createSnapshot();
},

promiseResolve(id) {
promiseResolve: common.mustCallAtLeast((id) => {
assert(promiseIds.includes(id));
createSnapshot();
},
}),

destroy(id) {
if (promiseIds.includes(id)) createSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const server = http.Server(common.mustCall((req, res) => {
}, 3));
server.listen(0);

server.on('listening', () => {
server.on('listening', common.mustCall(() => {
const agent = new http.Agent({ port: server.address().port, maxSockets: 1 });
const req = http.get({
port: server.address().port,
Expand Down Expand Up @@ -133,4 +133,4 @@ server.on('listening', () => {
}));
req.end();
}), 2);
});
}));
2 changes: 1 addition & 1 deletion test/parallel/test-https-agent-create-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const expectedHeader = /^HTTP\/1\.1 200 OK/;
const expectedBody = /hello world\n/;
const expectCertError = /^UNABLE_TO_VERIFY_LEAF_SIGNATURE$/;

const checkRequest = (socket, server) => {
function checkRequest(socket, server) {
let result = '';
socket.on('connect', common.mustCall((data) => {
socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-https-agent-keylog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const server = https.createServer({
});
});

const verifyKeylog = (line, tlsSocket) => {
const verifyKeylog = common.mustCallAtLeast((line, tlsSocket) => {
assert(Buffer.isBuffer(line));
assert.strictEqual(tlsSocket.encrypted, true);
};
});
server.on('keylog', common.mustCall(verifyKeylog, 10));
https.globalAgent.on('keylog', common.mustCall(verifyKeylog, 10));
11 changes: 4 additions & 7 deletions test/parallel/test-https-agent-servername.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ const server = https.Server(options, (req, res) => {
});


server.listen(0, function() {
server.listen(0, common.mustCall(function() {
https.get({
path: '/',
port: this.address().port,
rejectUnauthorized: true,
servername: 'agent1',
ca: options.ca
}, (res) => {
}, common.mustCall((res) => {
res.resume();
assert.strictEqual(res.statusCode, 200);
server.close();
}).on('error', (e) => {
console.log(e.message);
process.exit(1);
});
});
})).on('error', common.mustNotCall());
}));
4 changes: 2 additions & 2 deletions test/parallel/test-https-agent-sni.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const server = https.Server(options, function(req, res) {
res.end('hello world');
});

server.listen(0, function() {
server.listen(0, common.mustCall(function() {
function expectResponse(id) {
return common.mustCall(function(res) {
res.resume();
Expand Down Expand Up @@ -59,4 +59,4 @@ server.listen(0, function() {
servername: '',
rejectUnauthorized: false
}, expectResponse(false));
});
}));
8 changes: 4 additions & 4 deletions test/parallel/test-https-agent-unref-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ if (process.argv[2] === 'localhost') {
const net = require('net');
const server = net.createServer();
server.listen(0);
server.on('listening', () => {
server.on('listening', common.mustCall(() => {
const port = server.address().port;
const { fork } = require('child_process');
const child = fork(__filename, ['localhost', port], {});
child.on('close', (exit_code) => {
child.on('close', common.mustCall((exit_code) => {
server.close();
assert.strictEqual(exit_code, 0);
});
});
}));
}));
}
14 changes: 6 additions & 8 deletions test/parallel/test-https-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,23 @@ const N = 4;
const M = 4;


server.listen(0, () => {
server.listen(0, common.mustCall(() => {
for (let i = 0; i < N; i++) {
setTimeout(() => {
setTimeout(common.mustCall(() => {
for (let j = 0; j < M; j++) {
https.get({
path: '/',
port: server.address().port,
rejectUnauthorized: false
}, function(res) {
}, common.mustCall((res) => {
res.resume();
assert.strictEqual(res.statusCode, 200);
if (++responses === N * M) server.close();
}).on('error', (e) => {
throw e;
});
})).on('error', common.mustNotCall());
}
}, i);
}), i);
}
});
}));


process.on('exit', () => {
Expand Down
18 changes: 7 additions & 11 deletions test/parallel/test-https-autoselectfamily.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const options = {
// Test that happy eyeballs algorithm is properly implemented when using HTTP.

function _lookup(resolver, hostname, options, cb) {
resolver.resolve(hostname, 'ANY', (err, replies) => {
resolver.resolve(hostname, 'ANY', common.mustCall((err, replies) => {
assert.notStrictEqual(options.family, 4);

if (err) {
Expand All @@ -41,7 +41,7 @@ function _lookup(resolver, hostname, options, cb) {
}

return cb(null, hosts[0].address, hosts[0].family);
});
}));
}

function createDnsServer(ipv6Addr, ipv4Addr, cb) {
Expand Down Expand Up @@ -89,7 +89,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) {
autoSelectFamily: true,
servername: 'example.org',
},
(res) => {
common.mustCall((res) => {
assert.strictEqual(res.statusCode, 200);
res.setEncoding('utf-8');

Expand All @@ -104,7 +104,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) {
ipv4Server.close();
dnsServer.close();
}));
}
})
).end();
}));
}));
Expand All @@ -113,11 +113,7 @@ function createDnsServer(ipv6Addr, ipv4Addr, cb) {
// Test that IPV4 is NOT reached if IPV6 is reachable
if (common.hasIPv6) {
createDnsServer('::1', '127.0.0.1', common.mustCall(function({ dnsServer, lookup }) {
const ipv4Server = createServer(options, common.mustNotCall((req, res) => {
assert.strictEqual(req.socket.servername, 'example.org');
res.writeHead(200, { Connection: 'close' });
res.end('response-ipv4');
}));
const ipv4Server = createServer(options, common.mustNotCall());

const ipv6Server = createServer(options, common.mustCall((req, res) => {
assert.strictEqual(req.socket.servername, 'example.org');
Expand All @@ -137,7 +133,7 @@ if (common.hasIPv6) {
autoSelectFamily: true,
servername: 'example.org',
},
(res) => {
common.mustCall((res) => {
assert.strictEqual(res.statusCode, 200);
res.setEncoding('utf-8');

Expand All @@ -153,7 +149,7 @@ if (common.hasIPv6) {
ipv6Server.close();
dnsServer.close();
}));
}
})
).end();
}));
}));
Expand Down
Loading
Loading