11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst dgram = require('dgram'); 51cb0ef41Sopenharmony_ciconst dns = require('dns'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cifor (const ctor of [dns.Resolver, dns.promises.Resolver]) { 81cb0ef41Sopenharmony_ci for (const timeout of [null, true, false, '', '2']) { 91cb0ef41Sopenharmony_ci assert.throws(() => new ctor({ timeout }), { 101cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 111cb0ef41Sopenharmony_ci name: 'TypeError', 121cb0ef41Sopenharmony_ci }); 131cb0ef41Sopenharmony_ci } 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci for (const timeout of [-2, 4.2, 2 ** 31]) { 161cb0ef41Sopenharmony_ci assert.throws(() => new ctor({ timeout }), { 171cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 181cb0ef41Sopenharmony_ci name: 'RangeError', 191cb0ef41Sopenharmony_ci }); 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci for (const timeout of [-1, 0, 1]) new ctor({ timeout }); // OK 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cifor (const timeout of [0, 1, 2]) { 261cb0ef41Sopenharmony_ci const server = dgram.createSocket('udp4'); 271cb0ef41Sopenharmony_ci server.bind(0, '127.0.0.1', common.mustCall(() => { 281cb0ef41Sopenharmony_ci const resolver = new dns.Resolver({ timeout }); 291cb0ef41Sopenharmony_ci resolver.setServers([`127.0.0.1:${server.address().port}`]); 301cb0ef41Sopenharmony_ci resolver.resolve4('nodejs.org', common.mustCall((err) => { 311cb0ef41Sopenharmony_ci assert.throws(() => { throw err; }, { 321cb0ef41Sopenharmony_ci code: 'ETIMEOUT', 331cb0ef41Sopenharmony_ci name: 'Error', 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci server.close(); 361cb0ef41Sopenharmony_ci })); 371cb0ef41Sopenharmony_ci })); 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cifor (const timeout of [0, 1, 2]) { 411cb0ef41Sopenharmony_ci const server = dgram.createSocket('udp4'); 421cb0ef41Sopenharmony_ci server.bind(0, '127.0.0.1', common.mustCall(() => { 431cb0ef41Sopenharmony_ci const resolver = new dns.promises.Resolver({ timeout }); 441cb0ef41Sopenharmony_ci resolver.setServers([`127.0.0.1:${server.address().port}`]); 451cb0ef41Sopenharmony_ci resolver.resolve4('nodejs.org').catch(common.mustCall((err) => { 461cb0ef41Sopenharmony_ci assert.throws(() => { throw err; }, { 471cb0ef41Sopenharmony_ci code: 'ETIMEOUT', 481cb0ef41Sopenharmony_ci name: 'Error', 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci server.close(); 511cb0ef41Sopenharmony_ci })); 521cb0ef41Sopenharmony_ci })); 531cb0ef41Sopenharmony_ci} 54