Skip to content

Commit

Permalink
Add test for pool.end method
Browse files Browse the repository at this point in the history
  • Loading branch information
asadbek2021 committed Jun 12, 2024
1 parent 33e0f16 commit 009acb9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/pg-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ class Pool extends EventEmitter {
client.end(() => {
this.emit('remove', client)

if (typeof callback === "function") {
if (typeof callback === 'function') {
callback()
}
})
})
}

connect(cb) {
Expand Down Expand Up @@ -348,7 +348,7 @@ class Pool extends EventEmitter {
this.log('remove expended client')
}

return this._remove(client, this._pulseQueue.bind(this))
return this._remove(client, this._pulseQueue.bind(this))
}

const isExpired = this._expired.has(client)
Expand Down
10 changes: 10 additions & 0 deletions packages/pg-pool/test/ending.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ describe('pool ending', () => {
expect(res.rows[0].name).to.equal('brianc')
})
)

it('pool.end() - finish pending queries', async () => {
const pool = new Pool({ max: 20 })
let completed = 0
for (let x = 1; x <= 20; x++) {
pool.query('SELECT $1::text as name', ['brianc']).then(() => completed++)
}
await pool.end()
expect(completed).to.equal(20)
})
})

0 comments on commit 009acb9

Please sign in to comment.