File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,6 +111,42 @@ describe('lifecycle hooks', () => {
111111 await pool . end ( )
112112 } )
113113
114+ it ( 'cleans up clients after repeated hook failures' , async ( ) => {
115+ let errorCount = 0
116+ const pool = new Pool ( {
117+ max : 2 ,
118+ onConnect : ( ) => {
119+ if ( errorCount < 10 ) {
120+ errorCount ++
121+ throw new Error ( 'connect hook error' )
122+ }
123+ } ,
124+ } )
125+ for ( let i = 0 ; i < 10 ; i ++ ) {
126+ let threw = false
127+ try {
128+ await pool . connect ( )
129+ } catch ( err ) {
130+ threw = true
131+ expect ( err . message ) . to . equal ( 'connect hook error' )
132+ }
133+ expect ( threw ) . to . equal ( true )
134+ }
135+ expect ( errorCount ) . to . equal ( 10 )
136+ expect ( pool . totalCount ) . to . equal ( 0 )
137+ expect ( pool . idleCount ) . to . equal ( 0 )
138+ const client1 = await pool . connect ( )
139+ const res1 = await client1 . query ( 'SELECT 1 AS num' )
140+ expect ( res1 . rows [ 0 ] . num ) . to . equal ( 1 )
141+ const client2 = await pool . connect ( )
142+ const res2 = await client2 . query ( 'SELECT 2 AS num' )
143+ expect ( res2 . rows [ 0 ] . num ) . to . equal ( 2 )
144+ expect ( pool . totalCount ) . to . equal ( 2 )
145+ client1 . release ( )
146+ client2 . release ( )
147+ await pool . end ( )
148+ } )
149+
114150 it ( 'errors out the connect call if the connect hook throws' , async ( ) => {
115151 const pool = new Pool ( {
116152 onConnect : ( ) => {
You can’t perform that action at this time.
0 commit comments