@@ -55,4 +55,72 @@ describe('pool size of 1', () => {
5555 return yield pool . end ( )
5656 } )
5757 )
58+
59+ it (
60+ 'does not remove clients when at or below min' ,
61+ co . wrap ( function * ( ) {
62+ const pool = new Pool ( { max : 1 , min : 1 , idleTimeoutMillis : 10 } )
63+ const client = yield pool . connect ( )
64+ client . release ( )
65+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
66+ expect ( pool . idleCount ) . to . equal ( 1 )
67+ return yield pool . end ( )
68+ } )
69+ )
70+
71+ it (
72+ 'does remove clients when at or below min if maxUses is reached' ,
73+ co . wrap ( function * ( ) {
74+ const pool = new Pool ( { max : 1 , min : 1 , idleTimeoutMillis : 10 , maxUses : 1 } )
75+ const client = yield pool . connect ( )
76+ client . release ( )
77+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
78+ expect ( pool . idleCount ) . to . equal ( 0 )
79+ return yield pool . end ( )
80+ } )
81+ )
82+
83+ it (
84+ 'does remove clients when at or below min if maxLifetimeSeconds is reached' ,
85+ co . wrap ( function * ( ) {
86+ const pool = new Pool ( { max : 1 , min : 1 , idleTimeoutMillis : 10 , maxLifetimeSeconds : 1 } )
87+ const client = yield pool . connect ( )
88+ client . release ( )
89+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 1020 ) )
90+ expect ( pool . idleCount ) . to . equal ( 0 )
91+ return yield pool . end ( )
92+ } )
93+ )
94+ } )
95+
96+ describe ( 'pool size of 2' , ( ) => {
97+ it (
98+ 'does not remove clients when at or below min' ,
99+ co . wrap ( function * ( ) {
100+ const pool = new Pool ( { max : 2 , min : 2 , idleTimeoutMillis : 10 } )
101+ const client = yield pool . connect ( )
102+ const client2 = yield pool . connect ( )
103+ client . release ( )
104+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
105+ client2 . release ( )
106+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
107+ expect ( pool . idleCount ) . to . equal ( 2 )
108+ return yield pool . end ( )
109+ } )
110+ )
111+
112+ it (
113+ 'does remove clients when above min' ,
114+ co . wrap ( function * ( ) {
115+ const pool = new Pool ( { max : 2 , min : 1 , idleTimeoutMillis : 10 } )
116+ const client = yield pool . connect ( )
117+ const client2 = yield pool . connect ( )
118+ client . release ( )
119+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
120+ client2 . release ( )
121+ yield new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
122+ expect ( pool . idleCount ) . to . equal ( 1 )
123+ return yield pool . end ( )
124+ } )
125+ )
58126} )
0 commit comments