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:
Brian C 2017-06-18 14:09:18 -05:00 committed by GitHub
parent 5061068b04
commit f7b1edc7bb
2 changed files with 17 additions and 1 deletions

View File

@ -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) {

View File

@ -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) {