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>
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const { promises: dnsPromises } = require('dns');
|
|
const assert = require('assert');
|
|
const dgram = require('dgram');
|
|
|
|
const server = dgram.createSocket('udp4');
|
|
const resolver = new dnsPromises.Resolver();
|
|
|
|
server.bind(0, common.mustCall(async () => {
|
|
resolver.setServers([`127.0.0.1:${server.address().port}`]);
|
|
|
|
// Single promise
|
|
{
|
|
server.once('message', () => {
|
|
resolver.cancel();
|
|
});
|
|
|
|
const hostname = 'example0.org';
|
|
|
|
await assert.rejects(
|
|
resolver.resolve4(hostname),
|
|
{
|
|
code: 'ECANCELLED',
|
|
syscall: 'queryA',
|
|
hostname
|
|
}
|
|
);
|
|
}
|
|
|
|
// Multiple promises
|
|
{
|
|
server.once('message', () => {
|
|
resolver.cancel();
|
|
});
|
|
|
|
const assertions = [];
|
|
const assertionCount = 10;
|
|
|
|
for (let i = 1; i <= assertionCount; i++) {
|
|
const hostname = `example${i}.org`;
|
|
|
|
assertions.push(
|
|
assert.rejects(
|
|
resolver.resolve4(hostname),
|
|
{
|
|
code: 'ECANCELLED',
|
|
syscall: 'queryA',
|
|
hostname: hostname
|
|
}
|
|
)
|
|
);
|
|
}
|
|
|
|
await Promise.all(assertions);
|
|
}
|
|
|
|
server.close();
|
|
}));
|