Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

#51 - Fix to empty waiting clients queues in case of an error (via po…

…oyasencha -- manual merge)
  • Loading branch information...
commit 33f8b91b0f907e5b72bccde421ed2dffc691c9d4 1 parent 8bc7cb9
@coopernurse authored
Showing with 49 additions and 1 deletion.
  1. +3 −1 lib/generic-pool.js
  2. +46 −0 test/generic-pool.test.js
View
4 lib/generic-pool.js
@@ -255,7 +255,9 @@ exports.Pool = function (factory) {
}
if (err) {
count -= 1;
- clientCb(err, obj);
+ if (clientCb) {
+ clientCb(err, obj);
+ }
process.nextTick(function(){
dispense();
});
View
46 test/generic-pool.test.js
@@ -252,9 +252,55 @@ module.exports = {
assert.ok(client === null);
});
}
+
+ var called = false;
pool.acquire(function(err, client) {
assert.ok(err === null);
assert.equal(typeof client.id, 'number');
+ called = true;
+ });
+ beforeExit(function() {
+ assert.ok(called);
+ assert.equal(pool.waitingClientsCount(), 0);
+ });
+ },
+
+ 'handle creation errors for delayed creates' : function (beforeExit) {
+ var created = 0;
+ var pool = poolModule.Pool({
+ name : 'test6',
+ create : function(callback) {
+ if (created < 5) {
+ setTimeout(function() {
+ callback(new Error('Error occurred.'));
+ }, 0);
+ } else {
+ setTimeout(function() {
+ callback({ id : created });
+ }, 0);
+ }
+ created++;
+ },
+ destroy : function(client) { },
+ max : 1,
+ idleTimeoutMillis : 1000
+ });
+ // ensure that creation errors do not populate the pool.
+ for (var i = 0; i < 5; i++) {
+ pool.acquire(function(err, client) {
+ assert.ok(err instanceof Error);
+ assert.ok(client === null);
+ });
+ }
+ var called = false;
+ pool.acquire(function(err, client) {
+ assert.ok(err === null);
+ assert.equal(typeof client.id, 'number');
+ called = true;
+ });
+ beforeExit(function() {
+ assert.ok(called);
+ assert.equal(pool.waitingClientsCount(), 0);
});
},
Please sign in to comment.
Something went wrong with that request. Please try again.