11import  { expect }  from  'chai' ; 
22
33import  { ConnectionError }  from  '../lib/errors' ; 
4- import  { createNewPool ,  pgProxyServer ,   PROXY_SERVER_PORT }  from  './helpers' ; 
4+ import  { createNewPool ,  fakePgServer ,   removeAllClientAndShutdownPool ,   FAKE_PG_SERVER_PORT }  from  './helpers' ; 
55
6- const  connectionOptions  =  { port : PROXY_SERVER_PORT } ; 
6+ const  connectionOptions  =  { port : FAKE_PG_SERVER_PORT } ; 
77
88let  server ; 
99
1010describe ( 'Pool connection timeout;' ,  ( )  =>  { 
1111    before ( done  =>  { 
12-         server  =  pgProxyServer ( 250 ,   done ) ; 
12+         server  =  fakePgServer ( done ) ; 
1313    } ) ; 
1414
1515    after ( done  =>  { 
@@ -19,17 +19,21 @@ describe('Pool connection timeout;', () => {
1919    it ( 'should callback with an error if timeout is passed' ,  done  =>  { 
2020        const  pool  =  createNewPool ( { connectionTimeout : 150 } ,  connectionOptions ) ; 
2121
22-         pool . acquire ( ( err ,  client )  =>  { 
22+         pool . acquire ( async   ( err ,  client )  =>  { 
2323            try  { 
2424                expect ( err ) . to . be . an . instanceof ( ConnectionError ) ; 
2525                expect ( err . message ) . to . contain ( 'Connection request has timed out' ) ; 
2626                expect ( pool . idleCount ) . to . equal ( 0 ) ; 
2727                expect ( pool . totalCount ) . to . equal ( 1 ) ; 
2828                expect ( client ) . to . be . undefined ; 
2929
30-                 pool . shutdown ( done ) ; 
30+                 await  removeAllClientAndShutdownPool ( pool ) ; 
31+ 
32+                 done ( ) ; 
3133            }  catch  ( err )  { 
32-                 pool . shutdown ( ( )  =>  done ( err ) ) ; 
34+                 removeAllClientAndShutdownPool ( pool ) 
35+                     . then (  ( )  =>  done ( err ) ) 
36+                     . catch ( ( )  =>  done ( err ) ) ; 
3337            } 
3438        } ) ; 
3539    } ) ; 
@@ -58,14 +62,19 @@ describe('Pool connection timeout;', () => {
5862            expect ( pool . idleCount ) . to . equal ( 0 ) ; 
5963            expect ( pool . totalCount ) . to . equal ( 15 ) ; 
6064
61-             pool . shutdown ( done ) ; 
65+             await  removeAllClientAndShutdownPool ( pool ) ; 
66+ 
67+             done ( ) ; 
6268        }  catch  ( err )  { 
63-             pool . shutdown ( ( )  =>  done ( err ) ) ; 
69+             removeAllClientAndShutdownPool ( pool ) 
70+                 . then (  ( )  =>  done ( err ) ) 
71+                 . catch ( ( )  =>  done ( err ) ) ; 
6472        } 
6573    } ) ; 
6674
6775    it ( 'should timeout on checkout of used connection' ,  done  =>  { 
68-         const  pool  =  createNewPool ( { connectionTimeout : 400 ,  maxSize : 1 } ,  connectionOptions ) ; 
76+         const  pool  =  createNewPool ( { connectionTimeout : 400 ,  maxSize : 1 } ) ; 
77+ 
6978        try  { 
7079            pool . acquire ( ( err ,  client )  =>  { 
7180                expect ( err ) . to . be . undefined ; 
@@ -79,6 +88,7 @@ describe('Pool connection timeout;', () => {
7988                    expect ( pool . totalCount ) . to . equal ( 1 ) ; 
8089
8190                    ( pool  as  any ) . clients . entries ( ) . next ( ) . value [ 0 ] . release ( ) ; 
91+ 
8292                    pool . shutdown ( done ) ; 
8393                } ) ; 
8494            } ) ; 
@@ -88,7 +98,7 @@ describe('Pool connection timeout;', () => {
8898    } ) ; 
8999
90100    it ( 'should timeout on query if all clients are busy' ,  done  =>  { 
91-         const  pool  =  createNewPool ( { connectionTimeout : 400 ,  maxSize : 1 } ,   connectionOptions ) ; 
101+         const  pool  =  createNewPool ( { connectionTimeout : 400 ,  maxSize : 1 } ) ; 
92102
93103        pool . acquire ( ( err ,  client )  =>  { 
94104            expect ( err ) . to . be . undefined ; 
@@ -109,7 +119,7 @@ describe('Pool connection timeout;', () => {
109119    } ) ; 
110120
111121    it ( 'should recover from timeout errors' ,  done  =>  { 
112-         const  pool  =  createNewPool ( { connectionTimeout : 400 ,  maxSize : 1 } ,   connectionOptions ) ; 
122+         const  pool  =  createNewPool ( { connectionTimeout : 400 ,  maxSize : 1 } ) ; 
113123
114124        pool . acquire ( ( err ,  client )  =>  { 
115125            expect ( err ) . to . be . undefined ; 
0 commit comments