diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-07-27 19:03:11 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-08-01 19:57:24 +0200 |
commit | 732658e4cf0ab676040cdbad92f39b93fbacaa80 (patch) | |
tree | 38ff867ac0732dc201d70c1e1aec8bfd55869fce /test/parallel/test-dns-channel-cancel.js | |
parent | 6e05970494de273a934448a85c48006a2c0610b6 (diff) | |
download | node-new-732658e4cf0ab676040cdbad92f39b93fbacaa80.tar.gz |
dns: add channel.cancel()
This can be used to implement custom timeouts.
Fixes: https://github.com/nodejs/node/issues/7231
PR-URL: https://github.com/nodejs/node/pull/14518
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'test/parallel/test-dns-channel-cancel.js')
-rw-r--r-- | test/parallel/test-dns-channel-cancel.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/parallel/test-dns-channel-cancel.js b/test/parallel/test-dns-channel-cancel.js new file mode 100644 index 0000000000..797d61efb4 --- /dev/null +++ b/test/parallel/test-dns-channel-cancel.js @@ -0,0 +1,29 @@ +'use strict'; +const common = require('../common'); +const dnstools = require('../common/dns'); +const { Resolver } = require('dns'); +const assert = require('assert'); +const dgram = require('dgram'); + +const server = dgram.createSocket('udp4'); +const resolver = new Resolver(); + +server.bind(0, common.mustCall(() => { + resolver.setServers([`127.0.0.1:${server.address().port}`]); + resolver.resolve4('example.org', common.mustCall((err, res) => { + assert.strictEqual(err.code, 'ECANCELLED'); + assert.strictEqual(err.errno, 'ECANCELLED'); + assert.strictEqual(err.syscall, 'queryA'); + assert.strictEqual(err.hostname, 'example.org'); + server.close(); + })); +})); + +server.on('message', common.mustCall((msg, { address, port }) => { + const parsed = dnstools.parseDNSPacket(msg); + const domain = parsed.questions[0].domain; + assert.strictEqual(domain, 'example.org'); + + // Do not send a reply. + resolver.cancel(); +})); |