Skip to content

Commit

Permalink
test: de-flake test-dns-idna2008.js
Browse files Browse the repository at this point in the history
* use known well-behaved DNS server
* force pass on ESERVFAIL

PR-URL: nodejs#26473
Fixes: nodejs#25870
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
refack committed Mar 9, 2019
1 parent d57d099 commit 9613221
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions test/internet/test-dns-idna2008.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,41 @@
const { mustCall } = require('../common');
const assert = require('assert');
const dns = require('dns');
const { addresses } = require('../common/internet');

const [host, expectedAddress] = ['straße.de', '81.169.145.78'];
const fixture = {
hostname: 'straße.de',
expectedAddress: '81.169.145.78',
dnsServer: addresses.DNS4_SERVER
};

dns.lookup(host, mustCall((err, address) => {
// Explicitly use well behaved DNS servers that are known to be able to resolve
// the query (which is a.k.a xn--strae-oqa.de).
dns.setServers([fixture.dnsServer]);

dns.lookup(fixture.hostname, mustCall((err, address) => {
if (err && err.errno === 'ESERVFAIL') {
assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
return;
}
assert.ifError(err);
assert.strictEqual(address, expectedAddress);
assert.strictEqual(address, fixture.expectedAddress);
}));

dns.promises.lookup(host).then(mustCall(({ address }) => {
assert.strictEqual(address, expectedAddress);
dns.promises.lookup(fixture.hostname).then(mustCall(({ address }) => {
assert.strictEqual(address, fixture.expectedAddress);
}).catch((err) => {
if (err && err.errno === 'ESERVFAIL') {
assert.ok(err.message.includes('queryA ESERVFAIL straße.de'));
}
}));

dns.resolve4(host, mustCall((err, addresses) => {
dns.resolve4(fixture.hostname, mustCall((err, addresses) => {
assert.ifError(err);
assert.deepStrictEqual(addresses, [expectedAddress]);
assert.deepStrictEqual(addresses, [fixture.expectedAddress]);
}));

new dns.promises.Resolver().resolve4(host).then(mustCall((addresses) => {
assert.deepStrictEqual(addresses, [expectedAddress]);
const p = new dns.promises.Resolver().resolve4(fixture.hostname);
p.then(mustCall((addresses) => {
assert.deepStrictEqual(addresses, [fixture.expectedAddress]);
}));

0 comments on commit 9613221

Please sign in to comment.