Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add count for reuse of each connection and track connection 'freshness' #556

Merged
merged 1 commit into from
May 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ var pools = {
pool.destroy(client);
}
});

client.poolCount = 0;
return cb(null, client);
});
},
destroy: function(client) {
client._destroying = true;
client.poolCount = undefined;
client.end();
}
});
Expand All @@ -66,6 +67,7 @@ var pools = {
cb = domain.bind(cb);
}
if(err) return cb(err, null, function() {/*NOOP*/});
client.poolCount++;
cb(null, client, function(err) {
if(err) {
pool.destroy(client);
Expand Down
35 changes: 35 additions & 0 deletions test/unit/pool/basic-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,38 @@ test('fetching pool by object', function() {
});
assert.equal(p, p2);
});


test('pool#connect client.poolCount', function() {
var p = pools.getOrCreate(poolId++);
var tid;

setConnectTimeout = function() {
tid = setTimeout(function() {
throw new Error("Connection callback was never called");
}, 100);
}

setConnectTimeout();
p.connect(function(err, client, done) {
clearTimeout(tid);
assert.equal(client.poolCount, 1,
'after connect, poolCount should be 1');
done();
assert.equal(client.poolCount, 1,
'after returning client to pool, poolCount should still be 1');
setConnectTimeout();
p.connect(function(err, client, done) {
clearTimeout(tid);
assert.equal(client.poolCount, 2,
'after second connect, poolCount should be 2');
done();
setConnectTimeout();
p.destroyAllNow(function() {
clearTimeout(tid);
assert.equal(client.poolCount, undefined,
'after pool is destroyed, count should be undefined');
});
})
});
});