@@ -21,9 +21,10 @@ const server = https.createServer({
21
21
cert : fixtures . readKey ( 'agent8-cert.pem' ) ,
22
22
key : fixtures . readKey ( 'agent8-key.pem' ) ,
23
23
} , ( req , res ) => {
24
+ console . log ( `[Upstream server] responding to request for ${ inspect ( req . url ) } ` ) ;
24
25
requests . add ( `https://localhost:${ server . address ( ) . port } ${ req . url } ` ) ;
25
26
res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
26
- res . end ( `Response for ${ req . url } ` ) ;
27
+ res . end ( `Response for ${ inspect ( req . url ) } ` ) ;
27
28
} ) ;
28
29
29
30
server . listen ( 0 ) ;
@@ -54,7 +55,7 @@ https.globalAgent = new https.Agent({
54
55
55
56
const severHost = `localhost:${ server . address ( ) . port } ` ;
56
57
57
- let counter = testCases . length ;
58
+ let counter = 0 ;
58
59
const expectedUrls = new Set ( ) ;
59
60
const expectedProxyLogs = new Set ( ) ;
60
61
for ( const testCase of testCases ) {
@@ -69,15 +70,20 @@ for (const testCase of testCases) {
69
70
https . request ( url , ( res ) => {
70
71
res . on ( 'error' , common . mustNotCall ( ) ) ;
71
72
res . setEncoding ( 'utf8' ) ;
72
- res . on ( 'data' , ( ) => { } ) ;
73
- res . on ( 'end' , common . mustCall ( ( ) => {
74
- console . log ( `#${ counter -- } eneded response for: ${ inspect ( url ) } ` ) ;
73
+ res . on ( 'data' , ( data ) => {
74
+ console . log ( `[Proxy client] Received response from server for ${ inspect ( url ) } : ${ data . toString ( ) } ` ) ;
75
+ } ) ;
76
+ res . on ( 'close' , common . mustCall ( ( ) => {
77
+ console . log ( `[Proxy client] #${ ++ counter } closed request for: ${ inspect ( url ) } ` ) ;
75
78
// Finished all test cases.
76
- if ( counter === 0 ) {
77
- proxy . close ( ) ;
78
- server . close ( ) ;
79
- assert . deepStrictEqual ( requests , expectedUrls ) ;
80
- assert . deepStrictEqual ( new Set ( logs ) , expectedProxyLogs ) ;
79
+ if ( counter === testCases . length ) {
80
+ setImmediate ( ( ) => {
81
+ console . log ( 'All requests completed, shutting down.' ) ;
82
+ proxy . close ( ) ;
83
+ server . close ( ) ;
84
+ assert . deepStrictEqual ( requests , expectedUrls ) ;
85
+ assert . deepStrictEqual ( new Set ( logs ) , expectedProxyLogs ) ;
86
+ } ) ;
81
87
}
82
88
} ) ) ;
83
89
} ) . on ( 'error' , common . mustNotCall ( ) ) . end ( ) ;
0 commit comments