Skip to content

Commit 67f2b45

Browse files
committed
Added regression test for brianc#2556
1 parent c9f9caf commit 67f2b45

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: packages/pg/test/integration/gh-issues/2556-tests.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict'
2+
var helper = require('./../test-helper')
3+
var assert = require('assert')
4+
5+
var callbackError = new Error('TEST: Throw in callback')
6+
7+
const suite = new helper.Suite()
8+
9+
suite.test('it should cleanup client even if an error is thrown in a callback', (done) => {
10+
// temporarily replace the test framework's uncaughtException handlers
11+
// with a custom one that ignores the callbackError
12+
let original_handlers = process.listeners('uncaughtException')
13+
process.removeAllListeners('uncaughtException')
14+
process.on('uncaughtException', (err) => {
15+
if (err != callbackError) {
16+
original_handlers[0](err)
17+
}
18+
})
19+
20+
// throw an error in a callback and verify that a subsequent query works without error
21+
var client = helper.client()
22+
client.query('SELECT NOW()', (err) => {
23+
assert(!err)
24+
setTimeout(reuseClient, 50)
25+
throw callbackError
26+
})
27+
28+
function reuseClient() {
29+
client.query('SELECT NOW()', (err) => {
30+
assert(!err)
31+
32+
// restore the test framework's uncaughtException handlers
33+
for (let handler of original_handlers) {
34+
process.on('uncaughtException', handler)
35+
}
36+
37+
client.end(done)
38+
})
39+
}
40+
})

0 commit comments

Comments
 (0)