File tree 2 files changed +35
-1
lines changed
test/integration/gh-issues
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,7 @@ Client.prototype.end = function (cb) {
400
400
// if we have an active query we need to force a disconnect
401
401
// on the socket - otherwise a hung query could block end forever
402
402
this . connection . stream . destroy ( new Error ( 'Connection terminated by user' ) )
403
- return
403
+ return cb ? cb ( ) : Promise . resolve ( )
404
404
}
405
405
if ( cb ) {
406
406
this . connection . end ( )
Original file line number Diff line number Diff line change
1
+ "use strict"
2
+ var helper = require ( './../test-helper' )
3
+
4
+ const suite = new helper . Suite ( )
5
+
6
+ suite . test ( 'calling end during active query should return a promise' , ( done ) => {
7
+ const client = new helper . pg . Client ( )
8
+ let callCount = 0
9
+ // ensure both the query rejects and the end promise resolves
10
+ const after = ( ) => {
11
+ if ( ++ callCount > 1 ) {
12
+ done ( )
13
+ }
14
+ }
15
+ client . connect ( ) . then ( ( ) => {
16
+ client . query ( 'SELECT NOW()' ) . catch ( after )
17
+ client . end ( ) . then ( after )
18
+ } )
19
+ } )
20
+
21
+ suite . test ( 'calling end during an active query should call end callback' , ( done ) => {
22
+ const client = new helper . pg . Client ( )
23
+ let callCount = 0
24
+ // ensure both the query rejects and the end callback fires
25
+ const after = ( ) => {
26
+ if ( ++ callCount > 1 ) {
27
+ done ( )
28
+ }
29
+ }
30
+ client . connect ( ) . then ( ( ) => {
31
+ client . query ( 'SELECT NOW()' ) . catch ( after )
32
+ client . end ( after )
33
+ } )
34
+ } )
You can’t perform that action at this time.
0 commit comments