@@ -45,31 +45,35 @@ describe('report exclude network option', () => {
45
45
res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
46
46
res . end ( ) ;
47
47
} ) ;
48
+ let ipv6Available = true ;
48
49
const port = await new Promise ( ( resolve ) => server . listen ( 0 , async ( ) => {
49
50
await Promise . all ( [
50
51
fetch ( 'http://127.0.0.1:' + server . address ( ) . port ) ,
51
- fetch ( 'http://[::1]:' + server . address ( ) . port ) ,
52
+ fetch ( 'http://[::1]:' + server . address ( ) . port ) . catch ( ( ) => ipv6Available = false ) ,
52
53
] ) ;
53
54
resolve ( server . address ( ) . port ) ;
54
55
server . close ( ) ;
55
56
} ) ) ;
56
57
process . report . excludeNetwork = false ;
57
58
let report = process . report . getReport ( ) ;
58
59
let tcp = report . libuv . filter ( ( uv ) => uv . type === 'tcp' && uv . remoteEndpoint ?. port === port ) ;
59
- assert . strictEqual ( tcp . length , 2 ) ;
60
- const findHandle = ( host , local = true , ip4 = true ) => {
61
- return tcp . some (
60
+ assert . strictEqual ( tcp . length , ipv6Available ? 2 : 1 ) ;
61
+ const findHandle = ( local , ip4 = true ) => {
62
+ return tcp . find (
62
63
( { [ local ? 'localEndpoint' : 'remoteEndpoint' ] : ep } ) =>
63
- ( ep [ ip4 ? 'ip4' : 'ip6' ] === ( ip4 ? '127.0.0.1' : '::1' ) &&
64
- ( Array . isArray ( host ) ? host . includes ( ep . host ) : ep . host === host ) ) ,
65
- ) ;
64
+ ( ep [ ip4 ? 'ip4' : 'ip6' ] === ( ip4 ? '127.0.0.1' : '::1' ) ) ,
65
+ ) ?. [ local ? 'localEndpoint' : 'remoteEndpoint' ] ;
66
66
} ;
67
67
try {
68
- assert . ok ( findHandle ( 'localhost' ) , 'local localhost handle not found' ) ;
69
- assert . ok ( findHandle ( 'localhost' , false ) , 'remote localhost handle not found' ) ;
68
+ // The reverse DNS of 127.0.0.1 can be a lot of things other than localhost
69
+ // it could resolve to the server name for instance
70
+ assert . notStrictEqual ( findHandle ( true ) ?. host , '127.0.0.1' ) ;
71
+ assert . notStrictEqual ( findHandle ( false ) ?. host , '127.0.0.1' ) ;
70
72
71
- assert . ok ( findHandle ( [ 'localhost' , 'ip6-localhost' ] , true , false ) , 'local ip6-localhost handle not found' ) ;
72
- assert . ok ( findHandle ( [ 'localhost' , 'ip6-localhost' ] , false , false ) , 'remote ip6-localhost handle not found' ) ;
73
+ if ( ipv6Available ) {
74
+ assert . notStrictEqual ( findHandle ( true , false ) ?. host , '::1' ) ;
75
+ assert . notStrictEqual ( findHandle ( false , false ) ?. host , '::1' ) ;
76
+ }
73
77
} catch ( e ) {
74
78
throw new Error ( e . message + ' in ' + JSON . stringify ( tcp , null , 2 ) ) ;
75
79
}
@@ -79,12 +83,14 @@ describe('report exclude network option', () => {
79
83
tcp = report . libuv . filter ( ( uv ) => uv . type === 'tcp' && uv . remoteEndpoint ?. port === port ) ;
80
84
81
85
try {
82
- assert . strictEqual ( tcp . length , 2 ) ;
83
- assert . ok ( findHandle ( '127.0.0.1' ) , 'local 127.0.0.1 handle not found ' ) ;
84
- assert . ok ( findHandle ( '127.0.0.1' , false ) , 'remote 127.0.0.1 handle not found ' ) ;
86
+ assert . strictEqual ( tcp . length , ipv6Available ? 2 : 1 ) ;
87
+ assert . strictEqual ( findHandle ( true ) ?. host , '127.0.0.1' ) ;
88
+ assert . strictEqual ( findHandle ( false ) ?. host , '127.0.0.1' ) ;
85
89
86
- assert . ok ( findHandle ( '::1' , true , false ) , 'local ::1 handle not found' ) ;
87
- assert . ok ( findHandle ( '::1' , false , false ) , 'remote ::1 handle not found' ) ;
90
+ if ( ipv6Available ) {
91
+ assert . strictEqual ( findHandle ( true , false ) ?. host , '::1' ) ;
92
+ assert . strictEqual ( findHandle ( false , false ) ?. host , '::1' ) ;
93
+ }
88
94
} catch ( e ) {
89
95
throw new Error ( e . message + ' in ' + JSON . stringify ( tcp , null , 2 ) ) ;
90
96
}
0 commit comments