generic-pool
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -258,3 +258,8 @@ var PriorityQueue = function(size) { | ||
count -= 1; | ||
clientCb(err, obj); | ||
if (clientCb) { | ||
clientCb(err, obj); | ||
} | ||
process.nextTick(function(){ | ||
dispense(); | ||
}); | ||
} else { | ||
@@ -261,0 +266,0 @@ if (clientCb) { |
{ | ||
"name": "generic-pool", | ||
"description": "Generic resource pooling for Node.JS", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "James Cooper <james@bitmechanic.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -23,2 +23,7 @@ [![build status](https://secure.travis-ci.org/coopernurse/node-pool.png)](http://travis-ci.org/coopernurse/node-pool) | ||
2.0.2 - October 22 2012 | ||
- Fix #51, #48 - createResource() should check for null clientCb in err case (contributed by pooyasencha) | ||
- Merged #52 - fix bug of infinite wait when create object aync error (contributed by windyrobin) | ||
- Merged #53 - change the position of dispense and callback to ensure the time order (contributed by windyrobin) | ||
2.0.1 - August 29 2012 | ||
@@ -25,0 +30,0 @@ - Fix #44 - leak of 'err' and 'obj' in createResource() |
@@ -255,8 +255,54 @@ var assert = require('assert'); | ||
} | ||
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); | ||
}); | ||
}, | ||
'pooled decorator should acquire and release' : function (beforeExit) { | ||
@@ -515,2 +561,30 @@ var assertion_count = 0; | ||
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); | ||
}); | ||
} | ||
@@ -517,0 +591,0 @@ |
46504
923
315