File tree 1 file changed +13
-11
lines changed
1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -25,23 +25,25 @@ describe('idle timeout', () => {
25
25
it (
26
26
'times out and removes clients when others are also removed' ,
27
27
co . wrap ( function * ( ) {
28
- let currentClient = 1
29
28
const pool = new Pool ( { idleTimeoutMillis : 10 } )
30
29
const clientA = yield pool . connect ( )
31
30
const clientB = yield pool . connect ( )
32
- clientA . release ( )
33
- clientB . release ( new Error ( ) )
31
+ clientA . release ( ) // this will put clientA in the idle pool
32
+ clientB . release ( new Error ( ) ) // an error will cause clientB to be removed immediately
34
33
35
34
const removal = new Promise ( ( resolve ) => {
36
- pool . on ( 'remove' , ( ) => {
35
+ pool . on ( 'remove' , ( client ) => {
36
+ // clientB's stream may take a while to close, so we may get a remove
37
+ // event for it
38
+ // we only want to handle the remove event for clientA when it times out
39
+ // due to being idle
40
+ if ( client !== clientA ) {
41
+ return
42
+ }
43
+
37
44
expect ( pool . idleCount ) . to . equal ( 0 )
38
45
expect ( pool . totalCount ) . to . equal ( 0 )
39
-
40
- if ( currentClient >= 2 ) {
41
- resolve ( )
42
- } else {
43
- currentClient ++
44
- }
46
+ resolve ( )
45
47
} )
46
48
} )
47
49
@@ -50,7 +52,7 @@ describe('idle timeout', () => {
50
52
try {
51
53
yield Promise . race ( [ removal , timeout ] )
52
54
} finally {
53
- yield pool . end ( )
55
+ pool . end ( )
54
56
}
55
57
} )
56
58
)
You can’t perform that action at this time.
0 commit comments