Skip to content

Commit 8bd43a5

Browse files
committed
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.
1 parent 747485d commit 8bd43a5

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

packages/pg-pool/index.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 8 deletions
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)