mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
8c0ec0f85f
PR-URL: https://github.com/nodejs/node/pull/44432 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const { Resolver } = require('dns');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
|
|
const server = dgram.createSocket('udp4');
|
|
const resolver = new Resolver();
|
|
|
|
const desiredQueries = 11;
|
|
let finishedQueries = 0;
|
|
|
|
server.bind(0, common.mustCall(async () => {
|
|
resolver.setServers([`127.0.0.1:${server.address().port}`]);
|
|
|
|
const callback = common.mustCall((err, res) => {
|
|
assert.strictEqual(err.code, 'ECANCELLED');
|
|
assert.strictEqual(err.syscall, 'queryA');
|
|
assert.strictEqual(err.hostname, `example${finishedQueries}.org`);
|
|
|
|
finishedQueries++;
|
|
if (finishedQueries === desiredQueries) {
|
|
server.close();
|
|
}
|
|
}, desiredQueries);
|
|
|
|
const next = (...args) => {
|
|
callback(...args);
|
|
|
|
server.once('message', () => {
|
|
resolver.cancel();
|
|
});
|
|
|
|
// Multiple queries
|
|
for (let i = 1; i < desiredQueries; i++) {
|
|
resolver.resolve4(`example${i}.org`, callback);
|
|
}
|
|
};
|
|
|
|
server.once('message', () => {
|
|
resolver.cancel();
|
|
});
|
|
|
|
// Single query
|
|
resolver.resolve4('example0.org', next);
|
|
}));
|