mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Make client.end return promise with active query
This commit is contained in:
parent
d4bb51f08e
commit
66c6776f6e
@ -400,7 +400,7 @@ Client.prototype.end = function (cb) {
|
||||
// if we have an active query we need to force a disconnect
|
||||
// on the socket - otherwise a hung query could block end forever
|
||||
this.connection.stream.destroy(new Error('Connection terminated by user'))
|
||||
return
|
||||
return cb ? cb() : Promise.resolve()
|
||||
}
|
||||
if (cb) {
|
||||
this.connection.end()
|
||||
|
||||
34
test/integration/gh-issues/1382-tests.js
Normal file
34
test/integration/gh-issues/1382-tests.js
Normal file
@ -0,0 +1,34 @@
|
||||
"use strict"
|
||||
var helper = require('./../test-helper')
|
||||
|
||||
const suite = new helper.Suite()
|
||||
|
||||
suite.test('calling end during active query should return a promise', (done) => {
|
||||
const client = new helper.pg.Client()
|
||||
let callCount = 0
|
||||
// ensure both the query rejects and the end promise resolves
|
||||
const after = () => {
|
||||
if (++callCount > 1) {
|
||||
done()
|
||||
}
|
||||
}
|
||||
client.connect().then(() => {
|
||||
client.query('SELECT NOW()').catch(after)
|
||||
client.end().then(after)
|
||||
})
|
||||
})
|
||||
|
||||
suite.test('calling end during an active query should call end callback', (done) => {
|
||||
const client = new helper.pg.Client()
|
||||
let callCount = 0
|
||||
// ensure both the query rejects and the end callback fires
|
||||
const after = () => {
|
||||
if (++callCount > 1) {
|
||||
done()
|
||||
}
|
||||
}
|
||||
client.connect().then(() => {
|
||||
client.query('SELECT NOW()').catch(after)
|
||||
client.end(after)
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user