configurable idle timeout on pooled clients

This commit is contained in:
brianc 2011-08-11 21:52:29 -05:00
parent aa63f50437
commit c16c7f619d
4 changed files with 18 additions and 3 deletions

View File

@ -12,5 +12,7 @@ module.exports = {
rows: 0,
//number of connections to use in connection pool
//0 will disable connection pooling
poolSize: 10
poolSize: 10,
//duration of node-pool timeout
poolIdleTimeout: 30000
}

View File

@ -42,7 +42,8 @@ var makeConnectFunction = function(ClientConstructor) {
destroy: function(client) {
client.end();
},
max: defaults.poolSize
max: defaults.poolSize,
idleTimeoutMillis: defaults.poolIdleTimeout
});
return pool.acquire(cb);
}

View File

@ -0,0 +1,12 @@
var helper = require(__dirname + '/test-helper');
helper.pg.defaults.poolIdleTimeout = 200;
test('idle timeout', function() {
helper.pg.connect(helper.connectionString(), assert.calls(function(err, client) {
assert.isNull(err);
client.query('SELECT NOW()');
//just let this one time out
//test will hang if pool doesn't timeout
}));
});

View File

@ -6,7 +6,7 @@ helper.pg.defaults.password = helper.args.password;
helper.pg.defaults.database = helper.args.database;
helper.pg.defaults.port = helper.args.port;
helper.pg.defaults.host = helper.args.host;
helper.pg.defaults.poolIdleTimeout = 100;
var args = {
user: helper.args.user,
password: helper.args.password,