@@ -6,21 +6,55 @@ const dns = require('dns');
6
6
const { PerformanceObserver } = require ( 'perf_hooks' ) ;
7
7
8
8
const entries = [ ] ;
9
- const obs = new PerformanceObserver ( common . mustCallAtLeast ( ( items ) => {
9
+ const obs = new PerformanceObserver ( ( items ) => {
10
10
entries . push ( ...items . getEntries ( ) ) ;
11
- } ) ) ;
11
+ } ) ;
12
12
13
13
obs . observe ( { type : 'dns' } ) ;
14
14
15
- dns . lookup ( 'localhost' , ( ) => { } ) ;
15
+ let count = 0 ;
16
+
17
+ function inc ( ) {
18
+ count ++ ;
19
+ }
20
+
21
+ // If DNS resolution fails, skip it
22
+ // https://github.com/nodejs/node/issues/44003
23
+ dns . lookup ( 'localhost' , common . mustCall ( ( err ) => { ! err && inc ( ) ; } ) ) ;
24
+ dns . lookupService ( '127.0.0.1' , 80 , common . mustCall ( ( err ) => { ! err && inc ( ) ; } ) ) ;
25
+ dns . resolveAny ( 'localhost' , common . mustCall ( ( err ) => { ! err && inc ( ) ; } ) ) ;
26
+
27
+ dns . promises . lookup ( 'localhost' ) . then ( inc ) . catch ( ( ) => { } ) ;
28
+ dns . promises . lookupService ( '127.0.0.1' , 80 ) . then ( inc ) . catch ( ( ) => { } ) ;
29
+ dns . promises . resolveAny ( 'localhost' ) . then ( inc ) . catch ( ( ) => { } ) ;
16
30
17
31
process . on ( 'exit' , ( ) => {
18
- assert . strictEqual ( entries . length , 1 ) ;
32
+ assert . strictEqual ( entries . length , count ) ;
19
33
entries . forEach ( ( entry ) => {
20
34
assert . strictEqual ( ! ! entry . name , true ) ;
21
35
assert . strictEqual ( entry . entryType , 'dns' ) ;
22
36
assert . strictEqual ( typeof entry . startTime , 'number' ) ;
23
37
assert . strictEqual ( typeof entry . duration , 'number' ) ;
24
38
assert . strictEqual ( typeof entry . detail , 'object' ) ;
39
+ switch ( entry . name ) {
40
+ case 'lookup' :
41
+ assert . strictEqual ( typeof entry . detail . hostname , 'string' ) ;
42
+ assert . strictEqual ( typeof entry . detail . family , 'number' ) ;
43
+ assert . strictEqual ( typeof entry . detail . hints , 'number' ) ;
44
+ assert . strictEqual ( typeof entry . detail . verbatim , 'boolean' ) ;
45
+ assert . strictEqual ( Array . isArray ( entry . detail . addresses ) , true ) ;
46
+ break ;
47
+ case 'lookupService' :
48
+ assert . strictEqual ( typeof entry . detail . host , 'string' ) ;
49
+ assert . strictEqual ( typeof entry . detail . port , 'number' ) ;
50
+ assert . strictEqual ( typeof entry . detail . hostname , 'string' ) ;
51
+ assert . strictEqual ( typeof entry . detail . service , 'string' ) ;
52
+ break ;
53
+ case 'queryAny' :
54
+ assert . strictEqual ( typeof entry . detail . host , 'string' ) ;
55
+ assert . strictEqual ( typeof entry . detail . ttl , 'boolean' ) ;
56
+ assert . strictEqual ( Array . isArray ( entry . detail . result ) , true ) ;
57
+ break ;
58
+ }
25
59
} ) ;
26
60
} ) ;
0 commit comments