@@ -21,9 +21,10 @@ const server = https.createServer({
2121 cert : fixtures . readKey ( 'agent8-cert.pem' ) ,
2222 key : fixtures . readKey ( 'agent8-key.pem' ) ,
2323} , ( req , res ) => {
24+ console . log ( `[Upstream server] responding to request for ${ inspect ( req . url ) } ` ) ;
2425 requests . add ( `https://localhost:${ server . address ( ) . port } ${ req . url } ` ) ;
2526 res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
26- res . end ( `Response for ${ req . url } ` ) ;
27+ res . end ( `Response for ${ inspect ( req . url ) } ` ) ;
2728} ) ;
2829
2930server . listen ( 0 ) ;
@@ -54,7 +55,7 @@ https.globalAgent = new https.Agent({
5455
5556const severHost = `localhost:${ server . address ( ) . port } ` ;
5657
57- let counter = testCases . length ;
58+ let counter = 0 ;
5859const expectedUrls = new Set ( ) ;
5960const expectedProxyLogs = new Set ( ) ;
6061for ( const testCase of testCases ) {
@@ -69,15 +70,20 @@ for (const testCase of testCases) {
6970 https . request ( url , ( res ) => {
7071 res . on ( 'error' , common . mustNotCall ( ) ) ;
7172 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 ) } ` ) ;
7578 // 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+ } ) ;
8187 }
8288 } ) ) ;
8389 } ) . on ( 'error' , common . mustNotCall ( ) ) . end ( ) ;
0 commit comments