6216f6089f
a fix was provided in 5079c1e0c41f431ac2e02c40ebd875d8fbb34004; test is modeled on query-error-handling-tests.js; test both kill query and disconnection on prepared statement execution; make connection error string message consistent between native and non-native; disable test server-side kill for native as it hangs; sync can cause error to be emitted so we catch that; we also move _ending state before _send is called.
84 lines
2.5 KiB
JavaScript
84 lines
2.5 KiB
JavaScript
var helper = require(__dirname + '/test-helper');
|
|
var util = require('util');
|
|
|
|
function killIdleQuery(targetQuery) {
|
|
var client2 = new Client(helper.args);
|
|
var pidColName = 'procpid'
|
|
var queryColName = 'current_query';
|
|
client2.connect(assert.success(function() {
|
|
helper.versionGTE(client2, '9.2.0', assert.success(function(isGreater) {
|
|
if(isGreater) {
|
|
pidColName = 'pid';
|
|
queryColName = 'query';
|
|
}
|
|
var killIdleQuery = "SELECT " + pidColName + ", (SELECT pg_terminate_backend(" + pidColName + ")) AS killed FROM pg_stat_activity WHERE " + queryColName + " = $1";
|
|
client2.query(killIdleQuery, [targetQuery], assert.calls(function(err, res) {
|
|
assert.ifError(err);
|
|
assert.equal(res.rows.length, 1);
|
|
client2.end();
|
|
assert.emits(client2, 'end');
|
|
}));
|
|
}));
|
|
}));
|
|
}
|
|
|
|
test('query killed during query execution of prepared statement', function() {
|
|
if(helper.args.native) {
|
|
return false;
|
|
}
|
|
var client = new Client(helper.args);
|
|
client.connect(assert.success(function() {
|
|
var sleepQuery = 'select pg_sleep($1)';
|
|
var query1 = client.query({
|
|
name: 'sleep query',
|
|
text: sleepQuery,
|
|
values: [5] },
|
|
assert.calls(function(err, result) {
|
|
assert.equal(err.message, 'terminating connection due to administrator command');
|
|
}));
|
|
|
|
query1.on('error', function(err) {
|
|
assert.fail('Prepared statement should not emit error');
|
|
});
|
|
|
|
query1.on('row', function(row) {
|
|
assert.fail('Prepared statement should not emit row');
|
|
});
|
|
|
|
query1.on('end', function(err) {
|
|
assert.fail('Prepared statement when executed should not return before being killed');
|
|
});
|
|
|
|
killIdleQuery(sleepQuery);
|
|
}));
|
|
});
|
|
|
|
|
|
test('client end during query execution of prepared statement', function() {
|
|
var client = new Client(helper.args);
|
|
client.connect(assert.success(function() {
|
|
var sleepQuery = 'select pg_sleep($1)';
|
|
var query1 = client.query({
|
|
name: 'sleep query',
|
|
text: sleepQuery,
|
|
values: [5] },
|
|
assert.calls(function(err, result) {
|
|
assert.equal(err.message, 'Connection was ended during query');
|
|
}));
|
|
|
|
query1.on('error', function(err) {
|
|
assert.fail('Prepared statement should not emit error');
|
|
});
|
|
|
|
query1.on('row', function(row) {
|
|
assert.fail('Prepared statement should not emit row');
|
|
});
|
|
|
|
query1.on('end', function(err) {
|
|
assert.fail('Prepared statement when executed should not return before being killed');
|
|
});
|
|
|
|
client.end();
|
|
}));
|
|
});
|