@@ -4,12 +4,14 @@ const common = require('../common');
4
4
const assert = require ( 'assert' ) ;
5
5
const { internalBinding } = require ( 'internal/test/binding' ) ;
6
6
const cares = internalBinding ( 'cares_wrap' ) ;
7
+
8
+ // Stub `getaddrinfo` to *always* error. This has to be done before we load the
9
+ // `dns` module to guarantee that the `dns` module uses the stub.
10
+ cares . getaddrinfo = ( ) => internalBinding ( 'uv' ) . UV_ENOMEM ;
11
+
7
12
const dns = require ( 'dns' ) ;
8
13
const dnsPromises = dns . promises ;
9
14
10
- // Stub `getaddrinfo` to *always* error.
11
- cares . getaddrinfo = ( ) => internalBinding ( 'uv' ) . UV_ENOENT ;
12
-
13
15
{
14
16
const err = {
15
17
code : 'ERR_INVALID_ARG_TYPE' ,
@@ -144,15 +146,19 @@ dns.lookup('127.0.0.1', {
144
146
145
147
let tickValue = 0 ;
146
148
149
+ // Should fail due to stub.
147
150
dns . lookup ( 'example.com' , common . mustCall ( ( error , result , addressType ) => {
148
151
assert ( error ) ;
149
152
assert . strictEqual ( tickValue , 1 ) ;
150
- assert . strictEqual ( error . code , 'ENOENT ' ) ;
153
+ assert . strictEqual ( error . code , 'ENOMEM ' ) ;
151
154
const descriptor = Object . getOwnPropertyDescriptor ( error , 'message' ) ;
152
155
// The error message should be non-enumerable.
153
156
assert . strictEqual ( descriptor . enumerable , false ) ;
154
157
} ) ) ;
155
158
156
- // Make sure that the error callback is called
157
- // on next tick.
159
+ // Make sure that the error callback is called on next tick.
158
160
tickValue = 1 ;
161
+
162
+ // Should fail due to stub.
163
+ assert . rejects ( dnsPromises . lookup ( 'example.com' ) ,
164
+ { code : 'ENOMEM' , hostname : 'example.com' } ) ;
0 commit comments