mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
1904e7372d
PR-URL: https://github.com/nodejs/node/pull/33472 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
const dns = require('dns');
|
|
|
|
for (const ctor of [dns.Resolver, dns.promises.Resolver]) {
|
|
for (const timeout of [null, true, false, '', '2']) {
|
|
assert.throws(() => new ctor({ timeout }), {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError',
|
|
});
|
|
}
|
|
|
|
for (const timeout of [-2, 4.2, 2 ** 31]) {
|
|
assert.throws(() => new ctor({ timeout }), {
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
name: 'RangeError',
|
|
});
|
|
}
|
|
|
|
for (const timeout of [-1, 0, 1]) new ctor({ timeout }); // OK
|
|
}
|
|
|
|
for (const timeout of [0, 1, 2]) {
|
|
const server = dgram.createSocket('udp4');
|
|
server.bind(0, '127.0.0.1', common.mustCall(() => {
|
|
const resolver = new dns.Resolver({ timeout });
|
|
resolver.setServers([`127.0.0.1:${server.address().port}`]);
|
|
resolver.resolve4('nodejs.org', common.mustCall((err) => {
|
|
assert.throws(() => { throw err; }, {
|
|
code: 'ETIMEOUT',
|
|
name: 'Error',
|
|
});
|
|
server.close();
|
|
}));
|
|
}));
|
|
}
|
|
|
|
for (const timeout of [0, 1, 2]) {
|
|
const server = dgram.createSocket('udp4');
|
|
server.bind(0, '127.0.0.1', common.mustCall(() => {
|
|
const resolver = new dns.promises.Resolver({ timeout });
|
|
resolver.setServers([`127.0.0.1:${server.address().port}`]);
|
|
resolver.resolve4('nodejs.org').catch(common.mustCall((err) => {
|
|
assert.throws(() => { throw err; }, {
|
|
code: 'ETIMEOUT',
|
|
name: 'Error',
|
|
});
|
|
server.close();
|
|
}));
|
|
}));
|
|
}
|