Skip to content

Commit a4ef6ce

Browse files
authored
Fix error handling test (brianc#2789)
* Fix error handling test brianc#2569 introduced a bug in the test. The test never passed but because travis-ci lovingly broke the integration we had a long time ago the tests weren't run in CI until I merged. So, this fixes the tests & does a better job cleaning up the query in an errored state. * Update sponsors
1 parent 747485d commit a4ef6ce

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

SPONSORS.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ node-postgres is made possible by the helpful contributors from the community as
1313
- [simpleanalytics](https://simpleanalytics.com/)
1414
- [n8n.io](https://n8n.io/)
1515
- [mpirik](https://github.com/mpirik)
16+
- [@BLUE-DEVIL1134](https://github.com/BLUE-DEVIL1134)
17+
- [bubble.io](https://bubble.io/)
18+
- GitHub[https://github.com/github]
1619

1720
# Supporters
1821

packages/pg-pool/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ class Pool extends EventEmitter {
417417
client.release(err)
418418
if (err) {
419419
return cb(err)
420-
} else {
421-
return cb(undefined, res)
422420
}
421+
return cb(undefined, res)
423422
})
424423
} catch (err) {
424+
client.release(err)
425425
return cb(err)
426426
}
427427
})

packages/pg-pool/test/error-handling.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ describe('pool error handling', function () {
3838
})
3939

4040
it('Catches errors in client.query', async function () {
41-
await expect((new Pool()).query(null)).to.throwError()
42-
await expect(async () => {
43-
try {
44-
await (new Pool()).query(null)
45-
} catch (e) {
46-
console.log(e)
47-
}
48-
}).not.to.throwError()
41+
let caught = false
42+
const pool = new Pool()
43+
try {
44+
await pool.query(null)
45+
} catch (e) {
46+
caught = true
47+
}
48+
pool.end()
49+
expect(caught).to.be(true)
4950
})
5051

5152
describe('calling release more than once', () => {

0 commit comments

Comments
 (0)