File tree 2 files changed +38
-1
lines changed
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -41,12 +41,13 @@ var pools = {
41
41
pool . destroy ( client ) ;
42
42
}
43
43
} ) ;
44
-
44
+ client . poolCount = 0 ;
45
45
return cb ( null , client ) ;
46
46
} ) ;
47
47
} ,
48
48
destroy : function ( client ) {
49
49
client . _destroying = true ;
50
+ client . poolCount = undefined ;
50
51
client . end ( ) ;
51
52
}
52
53
} ) ;
@@ -66,6 +67,7 @@ var pools = {
66
67
cb = domain . bind ( cb ) ;
67
68
}
68
69
if ( err ) return cb ( err , null , function ( ) { /*NOOP*/ } ) ;
70
+ client . poolCount ++ ;
69
71
cb ( null , client , function ( err ) {
70
72
if ( err ) {
71
73
pool . destroy ( client ) ;
Original file line number Diff line number Diff line change @@ -177,3 +177,38 @@ test('fetching pool by object', function() {
177
177
} ) ;
178
178
assert . equal ( p , p2 ) ;
179
179
} ) ;
180
+
181
+
182
+ test ( 'pool#connect client.poolCount' , function ( ) {
183
+ var p = pools . getOrCreate ( poolId ++ ) ;
184
+ var tid ;
185
+
186
+ setConnectTimeout = function ( ) {
187
+ tid = setTimeout ( function ( ) {
188
+ throw new Error ( "Connection callback was never called" ) ;
189
+ } , 100 ) ;
190
+ }
191
+
192
+ setConnectTimeout ( ) ;
193
+ p . connect ( function ( err , client , done ) {
194
+ clearTimeout ( tid ) ;
195
+ assert . equal ( client . poolCount , 1 ,
196
+ 'after connect, poolCount should be 1' ) ;
197
+ done ( ) ;
198
+ assert . equal ( client . poolCount , 1 ,
199
+ 'after returning client to pool, poolCount should still be 1' ) ;
200
+ setConnectTimeout ( ) ;
201
+ p . connect ( function ( err , client , done ) {
202
+ clearTimeout ( tid ) ;
203
+ assert . equal ( client . poolCount , 2 ,
204
+ 'after second connect, poolCount should be 2' ) ;
205
+ done ( ) ;
206
+ setConnectTimeout ( ) ;
207
+ p . destroyAllNow ( function ( ) {
208
+ clearTimeout ( tid ) ;
209
+ assert . equal ( client . poolCount , undefined ,
210
+ 'after pool is destroyed, count should be undefined' ) ;
211
+ } ) ;
212
+ } )
213
+ } ) ;
214
+ } ) ;
You can’t perform that action at this time.
0 commit comments