Skip to content

Commit

Permalink
Fix race condition in release event test for pool (#2969)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianc committed May 1, 2023
1 parent b357e18 commit 0870442
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/pg-pool/test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ describe('events', function () {
expect(client).to.be.ok()
releaseCount++
})
const promises = []
for (let i = 0; i < 10; i++) {
pool.connect(function (err, client, release) {
if (err) return done(err)
release()
})
pool.query('SELECT now()')
promises.push(pool.query('SELECT now()'))
}
setTimeout(function () {
expect(releaseCount).to.be(20)
pool.end(done)
}, 100)
Promise.all(promises).then(() => {
pool.end(() => {
expect(releaseCount).to.be(20)
done()
})
})
})

it('emits release with an error if client is released due to an error', function (done) {
Expand All @@ -87,7 +90,6 @@ describe('events', function () {
expect(err).to.equal(undefined)
const releaseError = new Error('problem')
pool.once('release', function (err, errClient) {
console.log(err, errClient)
expect(err).to.equal(releaseError)
expect(errClient).to.equal(client)
pool.end(done)
Expand Down

0 comments on commit 0870442

Please sign in to comment.