@@ -6,21 +6,55 @@ const dns = require('dns');
66const { PerformanceObserver } = require ( 'perf_hooks' ) ;
77
88const entries = [ ] ;
9- const obs = new PerformanceObserver ( common . mustCallAtLeast ( ( items ) => {
9+ const obs = new PerformanceObserver ( ( items ) => {
1010 entries . push ( ...items . getEntries ( ) ) ;
11- } ) ) ;
11+ } ) ;
1212
1313obs . observe ( { type : 'dns' } ) ;
1414
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 ( ( ) => { } ) ;
1630
1731process . on ( 'exit' , ( ) => {
18- assert . strictEqual ( entries . length , 1 ) ;
32+ assert . strictEqual ( entries . length , count ) ;
1933 entries . forEach ( ( entry ) => {
2034 assert . strictEqual ( ! ! entry . name , true ) ;
2135 assert . strictEqual ( entry . entryType , 'dns' ) ;
2236 assert . strictEqual ( typeof entry . startTime , 'number' ) ;
2337 assert . strictEqual ( typeof entry . duration , 'number' ) ;
2438 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+ }
2559 } ) ;
2660} ) ;
0 commit comments