mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
If you throw an exception in a query callback the client will not pulse its internal query queue and therefor will never process any more queries or emit its own 'drain' event. I don't find this to be an issue in production code since I restart the process on exceptions, but it can break tests and cause things to 'hang'. My crude benchmarks show no noticable impact in perf from the try/catch/rethrow. :q
23 lines
877 B
JavaScript
23 lines
877 B
JavaScript
var helper = require(__dirname + '/test-helper');
|
|
var util = require('util');
|
|
|
|
test('error during query execution', function() {
|
|
var client = new Client(helper.args);
|
|
process.removeAllListeners('uncaughtException');
|
|
assert.emits(process, 'uncaughtException', function() {
|
|
assert.equal(client.activeQuery, null, 'should remove active query even if error happens in callback');
|
|
client.query('SELECT * FROM blah', assert.success(function(result) {
|
|
assert.equal(result.rows.length, 1);
|
|
client.end();
|
|
}));
|
|
});
|
|
client.connect(assert.success(function() {
|
|
client.query('CREATE TEMP TABLE "blah"(data text)', assert.success(function() {
|
|
var q = client.query('INSERT INTO blah(data) VALUES($1)', ['yo'], assert.success(function() {
|
|
assert.emits(client, 'drain');
|
|
throw new Error('WHOOOAAAHH!!');
|
|
}));
|
|
}));
|
|
}));
|
|
});
|