Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Fix _endCallback #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class Pool extends EventEmitter {
this.log('client failed to connect', err)
// remove the dead client from our list of clients
this._clients = this._clients.filter(c => c !== client)
if (!this._clients.length && this._endCallback) this._endCallback()
if (timeoutHit) {
err.message = 'Connection terminated due to connection timeout'
}
Expand Down
17 changes: 17 additions & 0 deletions test/connection-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ describe('connection timeout', () => {
})
})

it('should call _endCallback if Pool.end was called prior to receiving callback with error', (done) => {
const pool = new Pool({ connectionTimeoutMillis: 10, port: this.port })
let endCalled = false
pool.connect((err, client, release) => {
expect(err).to.be.an(Error)
expect(err.message).to.contain('timeout')
expect(client).to.equal(undefined)
expect(pool.idleCount).to.equal(0)
expect(endCalled).to.be(true)
done()
})
pool.end((err) => {
expect(err).to.be(undefined)
endCalled = true
})
})

it('should reject promise with an error if timeout is passed', (done) => {
const pool = new Pool({ connectionTimeoutMillis: 10, port: this.port })
pool.connect().catch(err => {
Expand Down