mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Add client to error event emitter (#65)
When the pool emits an error pass the client as the 2nd parameter to the `on('error')` handler.
This commit is contained in:
parent
5061068b04
commit
f7b1edc7bb
2
index.js
2
index.js
@ -90,7 +90,7 @@ Pool.prototype._create = function (cb) {
|
||||
this.log('connected client error:', e)
|
||||
this.pool.destroy(client)
|
||||
e.client = client
|
||||
this.emit('error', e)
|
||||
this.emit('error', e, client)
|
||||
}.bind(this))
|
||||
|
||||
client.connect(function (err) {
|
||||
|
||||
@ -60,6 +60,22 @@ describe('events', function () {
|
||||
pool.end(done)
|
||||
}, 40)
|
||||
})
|
||||
|
||||
it('emits error and client if an idle client in the pool hits an error', function (done) {
|
||||
var pool = new Pool()
|
||||
pool.connect(function (err, client) {
|
||||
expect(err).to.equal(null)
|
||||
client.release()
|
||||
setImmediate(function () {
|
||||
client.emit('error', new Error('problem'))
|
||||
})
|
||||
pool.once('error', function (err, errClient) {
|
||||
expect(err.message).to.equal('problem')
|
||||
expect(errClient).to.equal(client)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function mockClient (methods) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user