@@ -4,6 +4,7 @@ import https from "https";
44import { afterEach , beforeEach , describe , expect , test as it , vi } from "vitest" ;
55
66import { NodeHttpHandler } from "./node-http-handler" ;
7+ import { timing } from "./timing" ;
78
89vi . mock ( "http" , async ( ) => {
910 const actual = ( await vi . importActual ( "http" ) ) as any ;
@@ -52,6 +53,7 @@ import { request as hsRequest } from "https";
5253describe ( "NodeHttpHandler" , ( ) => {
5354 describe ( "constructor and #handle" , ( ) => {
5455 const randomMaxSocket = Math . round ( Math . random ( ) * 50 ) + 1 ;
56+ const randomSocketAcquisitionWarningTimeout = Math . round ( Math . random ( ) * 10000 ) + 1 ;
5557
5658 beforeEach ( ( ) => { } ) ;
5759
@@ -93,6 +95,21 @@ describe("NodeHttpHandler", () => {
9395 expect ( vi . mocked ( hRequest as any ) . mock . calls [ 0 ] [ 0 ] ?. agent . maxSockets ) . toEqual ( 50 ) ;
9496 } ) ;
9597
98+ it . each ( [
99+ [ "an options hash" , { socketAcquisitionWarningTimeout : randomSocketAcquisitionWarningTimeout } ] ,
100+ [
101+ "a provider" ,
102+ async ( ) => ( {
103+ socketAcquisitionWarningTimeout : randomSocketAcquisitionWarningTimeout ,
104+ } ) ,
105+ ] ,
106+ ] ) ( "sets socketAcquisitionWarningTimeout correctly when input is %s" , async ( _ , option ) => {
107+ vi . spyOn ( timing , "setTimeout" ) ;
108+ const nodeHttpHandler = new NodeHttpHandler ( option ) ;
109+ await nodeHttpHandler . handle ( { } as any ) ;
110+ expect ( vi . mocked ( timing . setTimeout ) . mock . calls [ 0 ] [ 1 ] ) . toBe ( randomSocketAcquisitionWarningTimeout ) ;
111+ } ) ;
112+
96113 it . each ( [
97114 [ "an options hash" , { httpAgent : new http . Agent ( { keepAlive : false , maxSockets : randomMaxSocket } ) } ] ,
98115 [
0 commit comments