Skip to content

Commit

Permalink
Fix error handling test (#2789)
Browse files Browse the repository at this point in the history
* Fix error handling test

#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
  • Loading branch information
brianc committed Aug 23, 2022
1 parent 747485d commit a4ef6ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions SPONSORS.md
Expand Up @@ -13,6 +13,9 @@ node-postgres is made possible by the helpful contributors from the community as
- [simpleanalytics](https://simpleanalytics.com/)
- [n8n.io](https://n8n.io/)
- [mpirik](https://github.com/mpirik)
- [@BLUE-DEVIL1134](https://github.com/BLUE-DEVIL1134)
- [bubble.io](https://bubble.io/)
- GitHub[https://github.com/github]

# Supporters

Expand Down
4 changes: 2 additions & 2 deletions packages/pg-pool/index.js
Expand Up @@ -417,11 +417,11 @@ class Pool extends EventEmitter {
client.release(err)
if (err) {
return cb(err)
} else {
return cb(undefined, res)
}
return cb(undefined, res)
})
} catch (err) {
client.release(err)
return cb(err)
}
})
Expand Down
17 changes: 9 additions & 8 deletions packages/pg-pool/test/error-handling.js
Expand Up @@ -38,14 +38,15 @@ describe('pool error handling', function () {
})

it('Catches errors in client.query', async function () {
await expect((new Pool()).query(null)).to.throwError()
await expect(async () => {
try {
await (new Pool()).query(null)
} catch (e) {
console.log(e)
}
}).not.to.throwError()
let caught = false
const pool = new Pool()
try {
await pool.query(null)
} catch (e) {
caught = true
}
pool.end()
expect(caught).to.be(true)
})

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

0 comments on commit a4ef6ce

Please sign in to comment.