Skip to content

Commit 0870442

Browse files
authored
Fix race condition in release event test for pool (#2969)
1 parent b357e18 commit 0870442

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/pg-pool/test/events.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,20 @@ describe('events', function () {
6868
expect(client).to.be.ok()
6969
releaseCount++
7070
})
71+
const promises = []
7172
for (let i = 0; i < 10; i++) {
7273
pool.connect(function (err, client, release) {
7374
if (err) return done(err)
7475
release()
7576
})
76-
pool.query('SELECT now()')
77+
promises.push(pool.query('SELECT now()'))
7778
}
78-
setTimeout(function () {
79-
expect(releaseCount).to.be(20)
80-
pool.end(done)
81-
}, 100)
79+
Promise.all(promises).then(() => {
80+
pool.end(() => {
81+
expect(releaseCount).to.be(20)
82+
done()
83+
})
84+
})
8285
})
8386

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

0 commit comments

Comments
 (0)