Skip to content

Commit 009acb9

Browse files
committed
Add test for pool.end method
1 parent 33e0f16 commit 009acb9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/pg-pool/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ class Pool extends EventEmitter {
167167
client.end(() => {
168168
this.emit('remove', client)
169169

170-
if (typeof callback === "function") {
170+
if (typeof callback === 'function') {
171171
callback()
172172
}
173-
})
173+
})
174174
}
175175

176176
connect(cb) {
@@ -348,7 +348,7 @@ class Pool extends EventEmitter {
348348
this.log('remove expended client')
349349
}
350350

351-
return this._remove(client, this._pulseQueue.bind(this))
351+
return this._remove(client, this._pulseQueue.bind(this))
352352
}
353353

354354
const isExpired = this._expired.has(client)

packages/pg-pool/test/ending.js

+10
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ describe('pool ending', () => {
3737
expect(res.rows[0].name).to.equal('brianc')
3838
})
3939
)
40+
41+
it('pool.end() - finish pending queries', async () => {
42+
const pool = new Pool({ max: 20 })
43+
let completed = 0
44+
for (let x = 1; x <= 20; x++) {
45+
pool.query('SELECT $1::text as name', ['brianc']).then(() => completed++)
46+
}
47+
await pool.end()
48+
expect(completed).to.equal(20)
49+
})
4050
})

0 commit comments

Comments
 (0)