node-postgres/test/integration/client/query-callback-error-tests.js
bmc 9b1c4facc2 Make query callback exceptions not break client
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
2013-04-19 09:09:28 -05:00

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!!');
}));
}));
}));
});