@@ -528,45 +528,56 @@ describe("networkProxy", () => {
528528 expect ( NodeHttpHandler ) . not . toHaveBeenCalled ( )
529529 } )
530530
531- it ( "should build both proxy agents without keeping connections alive" , ( ) => {
531+ it ( "should build both proxy agents with the keep- alive defaults of the direct route " , ( ) => {
532532 process . env . HTTPS_PROXY = "http://proxy.corp:3128"
533533
534534 expect ( createProxyRoutingRequestHandler ( ) ) . toBeDefined ( )
535535
536- // No agent options: an idle connection would outlive the request that opened it.
537- expect ( HttpProxyAgent ) . toHaveBeenCalledWith ( "http://proxy.corp:3128" )
538- expect ( HttpsProxyAgent ) . toHaveBeenCalledWith ( "http://proxy.corp:3128" )
536+ const agentOptions = { keepAlive : true , maxSockets : 50 }
537+ expect ( HttpProxyAgent ) . toHaveBeenCalledWith ( "http://proxy.corp:3128" , agentOptions )
538+ expect ( HttpsProxyAgent ) . toHaveBeenCalledWith ( "http://proxy.corp:3128" , agentOptions )
539539 const { proxied } = innerHandlers ( )
540540 expect ( proxied ?. options ?. httpAgent ) . toBe ( vi . mocked ( HttpProxyAgent ) . mock . instances [ 0 ] )
541541 expect ( proxied ?. options ?. httpsAgent ) . toBe ( vi . mocked ( HttpsProxyAgent ) . mock . instances [ 0 ] )
542542 } )
543543
544- it ( "should send a request through the proxy when NO_PROXY does not cover it" , ( ) => {
544+ it ( "should send a request through the proxy when NO_PROXY does not cover it" , async ( ) => {
545545 process . env . HTTPS_PROXY = "http://proxy.corp:3128"
546546 process . env . NO_PROXY = "example.com"
547547
548548 const handler = createProxyRoutingRequestHandler ( )
549+ const { direct, proxied } = innerHandlers ( )
550+ const response = { response : { statusCode : 200 } }
551+ proxied ?. handle . mockResolvedValue ( response )
552+
553+ // The request options carry the abort signal and timeout, so they must reach the route.
549554 const request = requestTo ( "bedrock-runtime.us-east-1.amazonaws.com" )
550- handler ?. handle ( request )
555+ const requestOptions = { abortSignal : new AbortController ( ) . signal , requestTimeout : 1234 }
556+ const result = handler ?. handle ( request , requestOptions )
551557
552- const { direct, proxied } = innerHandlers ( )
553- expect ( proxied ?. handle ) . toHaveBeenCalledWith ( request )
558+ expect ( proxied ?. handle ) . toHaveBeenCalledWith ( request , requestOptions )
554559 expect ( direct ?. handle ) . not . toHaveBeenCalled ( )
560+ await expect ( result ) . resolves . toBe ( response )
555561 } )
556562
557- it ( "should send a request directly when NO_PROXY covers its host" , ( ) => {
563+ it ( "should send a request directly when NO_PROXY covers its host" , async ( ) => {
558564 process . env . HTTPS_PROXY = "http://proxy.corp:3128"
559565 process . env . NO_PROXY = "amazonaws.com"
560566
561567 const handler = createProxyRoutingRequestHandler ( )
568+ const { direct, proxied } = innerHandlers ( )
569+ const response = { response : { statusCode : 200 } }
570+ direct ?. handle . mockResolvedValue ( response )
571+
562572 // The host is only known per request, which is the point of deciding here: indexed
563573 // file contents must not reach a proxy the user excluded.
564574 const request = requestTo ( "bedrock-runtime.eu-west-1.amazonaws.com" )
565- handler ?. handle ( request )
575+ const requestOptions = { abortSignal : new AbortController ( ) . signal , requestTimeout : 1234 }
576+ const result = handler ?. handle ( request , requestOptions )
566577
567- const { direct, proxied } = innerHandlers ( )
568- expect ( direct ?. handle ) . toHaveBeenCalledWith ( request )
578+ expect ( direct ?. handle ) . toHaveBeenCalledWith ( request , requestOptions )
569579 expect ( proxied ?. handle ) . not . toHaveBeenCalled ( )
580+ await expect ( result ) . resolves . toBe ( response )
570581 } )
571582
572583 it ( "should send every request directly when NO_PROXY is '*'" , ( ) => {
0 commit comments