2011-08-29 15:35:46 +08:00
|
|
|
var helper = require(__dirname + "/../test-helper");
|
|
|
|
var pg = require(__dirname + "/../../../lib");
|
|
|
|
helper.pg = pg;
|
|
|
|
|
|
|
|
//first make pool hold 2 clients
|
2011-11-22 11:42:43 +08:00
|
|
|
helper.pg.defaults.poolSize = 2;
|
2011-08-29 15:35:46 +08:00
|
|
|
|
|
|
|
var killIdleQuery = 'SELECT procpid, (SELECT pg_terminate_backend(procpid)) AS killed FROM pg_stat_activity WHERE current_query LIKE \'<IDLE>\'';
|
|
|
|
|
|
|
|
//get first client
|
2011-11-22 11:42:43 +08:00
|
|
|
helper.pg.connect(helper.config, assert.success(function(client) {
|
2011-08-29 15:35:46 +08:00
|
|
|
client.id = 1;
|
2011-11-22 11:42:43 +08:00
|
|
|
helper.pg.connect(helper.config, assert.success(function(client2) {
|
2011-08-29 15:35:46 +08:00
|
|
|
client2.id = 2;
|
|
|
|
//subscribe to the pg error event
|
2011-11-22 11:42:43 +08:00
|
|
|
assert.emits(helper.pg, 'error', function(error, brokenClient) {
|
2011-08-29 15:35:46 +08:00
|
|
|
assert.ok(error);
|
2011-09-14 07:18:44 +08:00
|
|
|
assert.ok(brokenClient);
|
|
|
|
assert.equal(client.id, brokenClient.id);
|
2011-11-22 11:42:43 +08:00
|
|
|
helper.pg.end();
|
2011-08-29 15:35:46 +08:00
|
|
|
});
|
|
|
|
//kill the connection from client
|
|
|
|
client2.query(killIdleQuery, assert.success(function(res) {
|
|
|
|
//check to make sure client connection actually was killed
|
2011-10-11 08:21:06 +08:00
|
|
|
assert.lengthIs(res.rows, 1);
|
2011-08-29 15:35:46 +08:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|