Skip to content

Commit b0d1619

Browse files
asadbek2021hjr3
authored andcommitted
Add test for pool.end method
1 parent e9466dd commit b0d1619

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/pg-pool/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ class Pool extends EventEmitter {
172172
client.end(() => {
173173
this.emit('remove', client)
174174

175-
if (typeof callback === "function") {
175+
if (typeof callback === 'function') {
176176
callback()
177177
}
178-
})
178+
})
179179
}
180180

181181
connect(cb) {
@@ -357,7 +357,7 @@ class Pool extends EventEmitter {
357357
this.log('remove expended client')
358358
}
359359

360-
return this._remove(client, this._pulseQueue.bind(this))
360+
return this._remove(client, this._pulseQueue.bind(this))
361361
}
362362

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

packages/pg-pool/test/ending.js

Lines changed: 10 additions & 0 deletions
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)