diff options
author | cjihrig <cjihrig@gmail.com> | 2018-06-11 14:56:33 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2018-06-20 13:35:27 -0400 |
commit | 7486c4d71060e2ae3e754cf01e8fb02696eacd13 (patch) | |
tree | 8b48c47271d474800f1222f729e93f477f3fd395 /test/parallel/test-dns-resolveany.js | |
parent | fea3595c2f92beb0d31feb93da1c972cc30e6fec (diff) | |
download | android-node-v8-7486c4d71060e2ae3e754cf01e8fb02696eacd13.tar.gz android-node-v8-7486c4d71060e2ae3e754cf01e8fb02696eacd13.tar.bz2 android-node-v8-7486c4d71060e2ae3e754cf01e8fb02696eacd13.zip |
dns: add promisified dns module
PR-URL: https://github.com/nodejs/node/pull/21264
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-dns-resolveany.js')
-rw-r--r-- | test/parallel/test-dns-resolveany.js | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/test/parallel/test-dns-resolveany.js b/test/parallel/test-dns-resolveany.js index 82f589147f..f9a6399cef 100644 --- a/test/parallel/test-dns-resolveany.js +++ b/test/parallel/test-dns-resolveany.js @@ -4,6 +4,9 @@ const dnstools = require('../common/dns'); const dns = require('dns'); const assert = require('assert'); const dgram = require('dgram'); +const dnsPromises = dns.promises; + +common.crashOnUnhandledRejection(); const answers = [ { type: 'A', address: '1.2.3.4', ttl: 123 }, @@ -36,18 +39,24 @@ server.on('message', common.mustCall((msg, { address, port }) => { questions: parsed.questions, answers: answers.map((answer) => Object.assign({ domain }, answer)), }), port, address); -})); +}, 2)); -server.bind(0, common.mustCall(() => { +server.bind(0, common.mustCall(async () => { const address = server.address(); dns.setServers([`127.0.0.1:${address.port}`]); + validateResults(await dnsPromises.resolveAny('example.org')); + dns.resolveAny('example.org', common.mustCall((err, res) => { assert.ifError(err); - // Compare copies with ttl removed, c-ares fiddles with that value. - assert.deepStrictEqual( - res.map((r) => Object.assign({}, r, { ttl: null })), - answers.map((r) => Object.assign({}, r, { ttl: null }))); + validateResults(res); server.close(); })); })); + +function validateResults(res) { + // Compare copies with ttl removed, c-ares fiddles with that value. + assert.deepStrictEqual( + res.map((r) => Object.assign({}, r, { ttl: null })), + answers.map((r) => Object.assign({}, r, { ttl: null }))); +} |