Skip to content

Commit b18c981

Browse files
committed
remove unused functions of pool
1 parent 0d19522 commit b18c981

File tree

3 files changed

+28
-55
lines changed

3 files changed

+28
-55
lines changed

lib/client-pool.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,11 @@ var defaults = require(__dirname + '/defaults');
44
module.exports = {
55
init: function(Client) {
66

7-
//wrap up common connection management boilerplate
8-
var connect = function(config, callback) {
9-
if(poolEnabled()) {
10-
return getPooledClient(config, callback)
11-
}
12-
13-
var client = new Client(config);
14-
client.connect();
15-
16-
var onError = function(error) {
17-
client.removeListener('connect', onReady);
18-
callback(error);
19-
}
20-
21-
var onReady = function() {
22-
client.removeListener('error', onError);
23-
callback(null, client);
24-
client.on('drain', client.end.bind(client));
25-
}
26-
27-
client.once('error', onError);
28-
29-
client.once('connect', onReady);
30-
}
31-
32-
337
//connection pool global cache
348
var clientPools = {
359
}
3610

37-
var poolEnabled = function() {
38-
return defaults.poolSize;
39-
}
40-
41-
var getPooledClient = function(config, callback) {
11+
var connect = function(config, callback) {
4212
//lookup pool using config as key
4313
//TODO this don't work so hot w/ object configs
4414
var pool = clientPools[config];

lib/utils.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ var Pool = function(maxSize, createFn) {
2020
this.items = [];
2121
this.waits = [];
2222
}
23+
2324
sys.inherits(Pool, events.EventEmitter);
25+
2426
var p = Pool.prototype;
2527

2628
p.checkOut = function(callback) {
29+
if(!this.maxSize) {
30+
return callback(null, this.createFn());
31+
}
2732
var len = 0;
2833
for(var i = 0, len = this.items.length; i < len; i++) {
2934
var item = this.items[i];
@@ -34,13 +39,7 @@ p.checkOut = function(callback) {
3439
//check if we can create a new item
3540
if(this.items.length < this.maxSize && this.createFn) {
3641
var result = this.createFn();
37-
var item = result;
38-
//create function can return item conforming to interface
39-
//of stored items to allow for create function to create
40-
//checked out items
41-
if(typeof item.checkedIn == "undefined") {
42-
var item = {ref: result, checkedIn: true}
43-
}
42+
var item = {ref: result, checkedIn: true}
4443
this.items.push(item);
4544
if(item.checkedIn) {
4645
return this._pulse(item, callback)

test/unit/utils-tests.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,28 @@ test('an empty pool', function() {
9191
})
9292
})
9393

94-
test('when creating async new pool members', function() {
95-
var count = 0;
96-
var pool = new Pool(3, function() {
97-
var item = {ref: {name: ++count}, checkedIn: false};
98-
process.nextTick(function() {
99-
pool.checkIn(item.ref)
100-
})
101-
return item;
94+
test('a pool with size of zero', function() {
95+
var index = 0;
96+
var pool = new Pool(0, function() {
97+
return index++;
98+
})
99+
test('checkin does nothing', function() {
100+
index = 0;
101+
pool.checkIn(301813);
102+
assert.equal(pool.checkOut(assert.calls(function(err, item) {
103+
assert.equal(item, 0);
104+
})));
102105
})
103-
test('one request recieves member', function() {
106+
test('always creates a new item', function() {
107+
index = 0;
104108
pool.checkOut(assert.calls(function(err, item) {
105-
assert.equal(item.name, 1)
106-
pool.checkOut(assert.calls(function(err, item) {
107-
assert.equal(item.name, 2)
108-
pool.checkOut(assert.calls(function(err, item) {
109-
assert.equal(item.name, 3)
110-
}))
111-
}))
109+
assert.equal(item, 0);
110+
}))
111+
pool.checkOut(assert.calls(function(err, item) {
112+
assert.equal(item, 1);
113+
}))
114+
pool.checkOut(assert.calls(function(err, item) {
115+
assert.equal(item, 2);
112116
}))
113117
})
114118
})
@@ -167,7 +171,7 @@ test('normalizing connection info', function() {
167171
assert.equal(output.database, process.env.USER);
168172
assert.equal(output.port, 5432);
169173
});
170-
174+
171175
test('uses overridden defaults', function() {
172176
defaults.host = "/var/run/postgresql";
173177
defaults.user = "boom";

0 commit comments

Comments
 (0)