Permalink
Browse files

Merge pull request #53 from windyrobin/5e1455f517e26a5b85a00307f93418…

…54a07156f2

change the position of dispense and callback to ensure the time order
  • Loading branch information...
2 parents 69180f3 + 5e1455f commit 2b5cea50540a2f88cf2a935c0880cc501ef78394 @coopernurse committed Oct 23, 2012
Showing with 29 additions and 0 deletions.
  1. +1 −0 lib/generic-pool.js
  2. +28 −0 test/generic-pool.test.js
View
@@ -255,6 +255,7 @@ exports.Pool = function (factory) {
}
if (err) {
count -= 1;
+ dispense();
clientCb(err, obj);
} else {
if (clientCb) {
@@ -511,6 +511,34 @@ module.exports = {
});
assert.equal(destroyCalled, true);
assert.equal(pool.availableObjectsCount(), 0);
+ },
+
+ 'do schedule again if error occured when creating new Objects async': function(beforeExit){
+ var factory = {
+ name: 'test',
+ create: function(callback) {
+ process.nextTick(function(){
+ var err = new Error('Create Error');
+ callback(err);
+ })
+ },
+ destroy: function(client) {},
+ max: 1,
+ idleTimeoutMillis: 100
+ };
+
+ var getFlag = 0;
+ var pool = poolModule.Pool(factory);
+ pool.acquire(function(){});
+ pool.acquire(function(err, obj){
+ getFlag = 1;
+ assert(err);
+ assert.equal(pool.availableObjectsCount(), 0);
+ });
+
+ beforeExit(function() {
+ assert.equal(getFlag, 1);
+ });
}

0 comments on commit 2b5cea5

Please sign in to comment.