From 9f594be75a691bf8a884528d4c07a9932f8d6672 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 12 May 2020 06:39:00 -0700 Subject: [PATCH] test: fix test-dns-idna2008 The DNS server will sometimes return an IPv6 address (as seen in nightly CI from time to time). Use `family` option to force IPv4. PR-URL: https://github.com/nodejs/node/pull/33367 Reviewed-By: Ben Noordhuis Reviewed-By: Luigi Pinca --- test/internet/test-dns-idna2008.js | 44 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/test/internet/test-dns-idna2008.js b/test/internet/test-dns-idna2008.js index 5a6a48b6fac39e..88c156303a06a0 100644 --- a/test/internet/test-dns-idna2008.js +++ b/test/internet/test-dns-idna2008.js @@ -16,31 +16,37 @@ const { addresses } = require('../common/internet'); const fixture = { hostname: 'straße.de', expectedAddress: '81.169.145.78', - dnsServer: addresses.DNS4_SERVER + dnsServer: addresses.DNS4_SERVER, + family: 4, }; -// Explicitly use well behaved DNS servers that are known to be able to resolve +// 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, fixture.expectedAddress); -})); +dns.lookup( + fixture.hostname, + { family: fixture.family }, + 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, fixture.expectedAddress); + }) +); -dns.promises.lookup(fixture.hostname).then(({ address }) => { - assert.strictEqual(address, fixture.expectedAddress); -}, (err) => { - if (err && err.errno === 'ESERVFAIL') { - assert.ok(err.message.includes('queryA ESERVFAIL straße.de')); - } else { - throw err; - } -}).finally(mustCall()); +dns.promises.lookup(fixture.hostname, { family: fixture.family }) + .then(({ address }) => { + assert.strictEqual(address, fixture.expectedAddress); + }, (err) => { + if (err && err.errno === 'ESERVFAIL') { + assert.ok(err.message.includes('queryA ESERVFAIL straße.de')); + } else { + throw err; + } + }).finally(mustCall()); dns.resolve4(fixture.hostname, mustCall((err, addresses) => { if (err && err.errno === 'ESERVFAIL') {