Skip to content

Commit 4513fe4

Browse files
committed
fix tests on older versions of postgres
1 parent 2c6a932 commit 4513fe4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

test/integration/connection-pool/error-tests.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ pg.connect(helper.config, assert.success(function(client, done) {
1313
client2.id = 2;
1414
var pidColName = 'procpid'
1515
helper.versionGTE(client2, '9.2.0', assert.success(function(isGreater) {
16-
if(isGreater) {
17-
pidColName = 'pid';
16+
var killIdleQuery = 'SELECT pid, (SELECT pg_terminate_backend(pid)) AS killed FROM pg_stat_activity WHERE state = $1';
17+
var params = ['idle'];
18+
if(!isGreater) {
19+
killIdleQuery = 'SELECT procpid, (SELECT pg_terminate_backend(procpid)) AS killed FROM pg_stat_activity WHERE current_query LIKE $1';
20+
params = ['%IDLE%']
1821
}
19-
var killIdleQuery = 'SELECT ' + pidColName + ', (SELECT pg_terminate_backend(' + pidColName + ')) AS killed FROM pg_stat_activity WHERE state = $1';
2022
done2();
2123
//subscribe to the pg error event
2224
assert.emits(pg, 'error', function(error, brokenClient) {
@@ -25,7 +27,7 @@ pg.connect(helper.config, assert.success(function(client, done) {
2527
assert.equal(client.id, brokenClient.id);
2628
});
2729
//kill the connection from client
28-
client2.query(killIdleQuery, ['idle'], assert.success(function(res) {
30+
client2.query(killIdleQuery, params, assert.success(function(res) {
2931
//check to make sure client connection actually was killed
3032
assert.lengthIs(res.rows, 1);
3133
pg.end();

0 commit comments

Comments
 (0)