forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dns: make dns.Resolver timeout configurable
PR-URL: nodejs#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>
- Loading branch information
1 parent
7774458
commit 1904e73
Showing
5 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'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(); | ||
})); | ||
})); | ||
} |