Skip to content
Closed
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
40 changes: 22 additions & 18 deletions test/parallel/test-async-wrap-pop-id-during-load.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
'use strict';

require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');

if (process.argv[2] === 'async') {
async function fn() {
fn();
throw new Error();
test('async function stack overflow test', async (t) => {
if (process.argv[2] === 'async') {
async function fn() {
fn();
throw new Error();
}
await (async function() { await fn(); })();
}
return (async function() { await fn(); })();
}

const assert = require('assert');
const { spawnSync } = require('child_process');
const ret = spawnSync(
process.execPath,
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);

const ret = spawnSync(
process.execPath,
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);
assert.strictEqual(ret.status, 0,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
// Expecting exit code 7, as the test triggers a stack overflow
assert.strictEqual(ret.status, 7,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
});
98 changes: 52 additions & 46 deletions test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
const assert = require('assert');

const dns = require('dns');
require('../common');

const { test } = require('node:test');
const assert = require('node:assert');
const dns = require('node:dns');
const dnsPromises = dns.promises;

(async function() {
test('dns promises lookup', async (t) => {
let res;

res = await dnsPromises.lookup(null);
Expand All @@ -40,54 +42,58 @@ const dnsPromises = dns.promises;
res = await dnsPromises.lookup('::1');
assert.strictEqual(res.address, '::1');
assert.strictEqual(res.family, 6);
})().then(common.mustCall());
});

// Try resolution without hostname.
dns.lookup(null, common.mustSucceed((result, addressType) => {
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
}));
test('dns callback lookup', (t) => {
dns.lookup(null, (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
});

dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
dns.lookup('127.0.0.1', (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
});

dns.lookup('::1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
}));
dns.lookup('::1', (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
});
});

[
// Try calling resolve with an unsupported type.
'HI',
// Try calling resolve with an unsupported type that's an object key
'toString',
].forEach((val) => {
const err = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'rrtype' is invalid. Received '${val}'`,
};
test('unsupported rrtype resolves', (t) => {
[
// Try calling resolve with an unsupported type.
'HI',
// Try calling resolve with an unsupported type that's an object key
'toString',
].forEach((val) => {
const err = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'rrtype' is invalid. Received '${val}'`,
};

assert.throws(
() => dns.resolve('www.google.com', val),
err
);
assert.throws(
() => dns.resolve('www.google.com', val),
err
);

assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
});
});

// Windows doesn't usually have an entry for localhost 127.0.0.1 in
// C:\Windows\System32\drivers\etc\hosts
// so we disable this test on Windows.
// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1
if (!common.isWindows && !common.isIBMi) {
dns.reverse('127.0.0.1', common.mustSucceed((domains) => {
assert.ok(Array.isArray(domains));
}));
test('reverse DNS lookup (non-Windows, non-IBMi)', async (t) => {
if (!process.platform.startsWith('win') && process.platform !== 'aix') {
dns.reverse('127.0.0.1', (err, domains) => {
assert.strictEqual(err, null);
assert.ok(Array.isArray(domains));
});

(async function() {
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
})().then(common.mustCall());
}
const domains = await dnsPromises.reverse('127.0.0.1');
assert.ok(Array.isArray(domains));
}
});
18 changes: 10 additions & 8 deletions test/parallel/test-double-tls-server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict';
const common = require('../common');
const assert = require('assert');
if (!common.hasCrypto) common.skip('missing crypto');
const fixtures = require('../common/fixtures');
const tls = require('tls');
const net = require('net');
const assert = require('node:assert');

if (!common.hasCrypto) common.skip('missing crypto');

const { test } = require('node:test');
const tls = require('node:tls');
const net = require('node:net');

// Sending tls data on a server TLSSocket with an active write led to a crash:
//
Expand All @@ -27,7 +30,7 @@ const net = require('net');

const serverReplaySize = 2 * 1024 * 1024;

(async function() {
test('TLS double handshake test', async (t) => {
const tlsClientHello = await getClientHello();

const subserver = tls.createServer({
Expand Down Expand Up @@ -57,8 +60,7 @@ const serverReplaySize = 2 * 1024 * 1024;
subserver.emit('connection', serverTlsSock);
});


function startClient() {
async function startClient() {
const clientTlsSock = tls.connect({
host: '127.0.0.1',
port: server.address().port,
Expand All @@ -81,7 +83,7 @@ const serverReplaySize = 2 * 1024 * 1024;
// In reality, one may want to send a HTTP CONNECT before starting this double TLS
clientTlsSock.write(tlsClientHello);
}
})().then(common.mustCall());
});

function getClientHello() {
return new Promise((resolve) => {
Expand Down
30 changes: 21 additions & 9 deletions test/parallel/test-eventtarget-once-twice.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
'use strict';
const common = require('../common');
const { once } = require('events');
const { once } = require('node:events');
const { test } = require('node:test');

const et = new EventTarget();
(async function() {
await once(et, 'foo');
await once(et, 'foo');
})().then(common.mustCall());
test('EventTarget test', async () => {
const et = new EventTarget();

et.dispatchEvent(new Event('foo'));
setImmediate(() => {
// Use `once` to listen for the 'foo' event twice
const promise1 = once(et, 'foo');
const promise2 = once(et, 'foo');

// Dispatch the first event
et.dispatchEvent(new Event('foo'));
});

// Dispatch the second event in the next tick to ensure it's awaited properly
setImmediate(() => {
et.dispatchEvent(new Event('foo'));
});

// Await both promises to ensure both 'foo' events are captured
await promise1;
await promise2;

// Test automatically completes after all asynchronous operations finish
}).then(common.mustCall());
20 changes: 11 additions & 9 deletions test/parallel/test-filehandle-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const { test } = require('node:test');

// Test that using FileHandle.close to close an already-closed fd fails
// with EBADF.

(async function() {
test('FileHandle.close should fail with EBADF when closing an already closed fd', async () => {
const fh = await fs.promises.open(__filename);
fs.closeSync(fh.fd);

await assert.rejects(() => fh.close(), {
code: 'EBADF',
syscall: 'close'
});
})().then(common.mustCall());
// Test that closing an already closed fd results in EBADF
await assert.rejects(
() => fh.close(),
{
code: 'EBADF',
syscall: 'close'
}
);
}).then(common.mustCall());
36 changes: 18 additions & 18 deletions test/parallel/test-fs-promises-file-handle-aggregate-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
const common = require('../common');
const tmpdir = require('../common/tmpdir');

// The following tests validate aggregate errors are thrown correctly
// when both an operation and close throw.
const { test } = require('node:test');
const { readFile, writeFile, truncate, lchmod } = require('node:fs/promises');
const { FileHandle } = require('internal/fs/promises');

const {
readFile,
writeFile,
truncate,
lchmod,
} = require('fs/promises');
const {
FileHandle,
} = require('internal/fs/promises');

const assert = require('assert');
const assert = require('node:assert');
const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd');

let count = 0;

async function createFile() {
const filePath = tmpdir.resolve(`aggregate_errors_${++count}.txt`);
await writeFile(filePath, 'content');
Expand All @@ -45,27 +37,35 @@ async function checkAggregateError(op) {
const opError = new Error('INTERNAL_ERROR');
opError.code = 123;
throw opError;
}
},
});

await assert.rejects(op(filePath), common.mustCall((err) => {
// Perform the operation and check the aggregate error
await assert.rejects(op(filePath), (err) => {
assert.strictEqual(err.name, 'AggregateError');
assert.strictEqual(err.code, 123);
assert.strictEqual(err.errors.length, 2);

// Check the individual errors
assert.strictEqual(err.errors[0].message, 'INTERNAL_ERROR');
assert.strictEqual(err.errors[0].code, 123);

assert.strictEqual(err.errors[1].message, 'CLOSE_ERROR');
assert.strictEqual(err.errors[1].code, 456);

return true;
}));
});
} finally {
Object.defineProperty(FileHandle.prototype, 'fd', originalFd);
}
}
(async function() {

test('Test aggregate errors for file operations', async () => {
tmpdir.refresh();
await checkAggregateError((filePath) => truncate(filePath));
await checkAggregateError((filePath) => readFile(filePath));
await checkAggregateError((filePath) => writeFile(filePath, '123'));
if (common.isMacOS) {
await checkAggregateError((filePath) => lchmod(filePath, 0o777));
}
})().then(common.mustCall());
});
Loading
Loading