@@ -58,6 +58,88 @@ tape('forever', function(t) {
5858 } )
5959} )
6060
61+ tape ( 'forever, should use same agent in sequential requests' , function ( t ) {
62+ var r = request . defaults ( {
63+ forever : true
64+ } )
65+ var req1 = r ( 'http://localhost:6767' )
66+ var req2 = r ( 'http://localhost:6767/somepath' )
67+ req1 . abort ( )
68+ req2 . abort ( )
69+ if ( typeof req1 . agent . destroy === 'function' ) {
70+ req1 . agent . destroy ( )
71+ }
72+ if ( typeof req2 . agent . destroy === 'function' ) {
73+ req2 . agent . destroy ( )
74+ }
75+ t . equal ( req1 . agent , req2 . agent )
76+ t . end ( )
77+ } )
78+
79+ tape ( 'forever, should use same agent in sequential requests(with pool.maxSockets)' , function ( t ) {
80+ var r = request . defaults ( {
81+ forever : true ,
82+ pool : { maxSockets : 1024 }
83+ } )
84+ var req1 = r ( 'http://localhost:6767' )
85+ var req2 = r ( 'http://localhost:6767/somepath' )
86+ req1 . abort ( )
87+ req2 . abort ( )
88+ if ( typeof req1 . agent . destroy === 'function' ) {
89+ req1 . agent . destroy ( )
90+ }
91+ if ( typeof req2 . agent . destroy === 'function' ) {
92+ req2 . agent . destroy ( )
93+ }
94+ t . equal ( req1 . agent . maxSockets , 1024 )
95+ t . equal ( req1 . agent , req2 . agent )
96+ t . end ( )
97+ } )
98+
99+ tape ( 'forever, should use same agent in request() and request.verb' , function ( t ) {
100+ var r = request . defaults ( {
101+ forever : true ,
102+ pool : { maxSockets : 1024 }
103+ } )
104+ var req1 = r ( 'http://localhost:6767' )
105+ var req2 = r . get ( 'http://localhost:6767' )
106+ req1 . abort ( )
107+ req2 . abort ( )
108+ if ( typeof req1 . agent . destroy === 'function' ) {
109+ req1 . agent . destroy ( )
110+ }
111+ if ( typeof req2 . agent . destroy === 'function' ) {
112+ req2 . agent . destroy ( )
113+ }
114+ t . equal ( req1 . agent . maxSockets , 1024 )
115+ t . equal ( req1 . agent , req2 . agent )
116+ t . end ( )
117+ } )
118+
119+ tape ( 'should use different agent if pool option specified' , function ( t ) {
120+ var r = request . defaults ( {
121+ forever : true ,
122+ pool : { maxSockets : 1024 }
123+ } )
124+ var req1 = r ( 'http://localhost:6767' )
125+ var req2 = r . get ( {
126+ url : 'http://localhost:6767' ,
127+ pool : { maxSockets : 20 }
128+ } )
129+ req1 . abort ( )
130+ req2 . abort ( )
131+ if ( typeof req1 . agent . destroy === 'function' ) {
132+ req1 . agent . destroy ( )
133+ }
134+ if ( typeof req2 . agent . destroy === 'function' ) {
135+ req2 . agent . destroy ( )
136+ }
137+ t . equal ( req1 . agent . maxSockets , 1024 )
138+ t . equal ( req2 . agent . maxSockets , 20 )
139+ t . notEqual ( req1 . agent , req2 . agent )
140+ t . end ( )
141+ } )
142+
61143tape ( 'cleanup' , function ( t ) {
62144 s . close ( function ( ) {
63145 t . end ( )
0 commit comments