Skip to content

Commit

Permalink
Make pool name consistent on missing config params (#1279)
Browse files Browse the repository at this point in the history
* Going red: using a config object creates two pools when missing some params

It should only create a pool in a consistent way, even if some params
are not provided in the first place.

* Delay the pool name generation to make it consistent between calls

* Don't fallback to empty object as config is already defined
  • Loading branch information
Raul Ochoa authored and brianc committed May 24, 2017
1 parent e5f0e5d commit 4cd56cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ PG.prototype.connect = function(config, callback) {
callback = config;
config = null;
}
var poolName = JSON.stringify(config || {});
if (typeof config == 'string') {
config = new ConnectionParameters(config);
}
Expand All @@ -66,6 +65,7 @@ PG.prototype.connect = function(config, callback) {
config.idleTimeoutMillis = config.idleTimeoutMillis || config.poolIdleTimeout || defaults.poolIdleTimeout;
config.log = config.log || config.poolLog || defaults.poolLog;

var poolName = JSON.stringify(config);
this._pools[poolName] = this._pools[poolName] || new this.Pool(config);
var pool = this._pools[poolName];
if(!pool.listeners('error').length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var helper = require(__dirname + "/../test-helper");
var pg = require(__dirname + "/../../../lib");

pg.connect(helper.config, assert.success(function(client, done) {
assert.equal(Object.keys(pg._pools).length, 1);
pg.connect(helper.config, assert.success(function(client2, done2) {
assert.equal(Object.keys(pg._pools).length, 1);

done();
done2();
pg.end();
}));
}));

0 comments on commit 4cd56cc

Please sign in to comment.