Skip to content

Commit

Permalink
pool.destroy didn't re-dispense resources (#173)
Browse files Browse the repository at this point in the history
* pool.destroy didn't trigger dispensing resources
  • Loading branch information
binux authored and James Butler committed Dec 28, 2016
1 parent 58c275c commit 2ac9db9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ class Pool extends EventEmitter {

pooledResource.deallocate()
this._destroy(pooledResource)

this._dispense()
return this._Promise.resolve()
}

Expand Down
66 changes: 66 additions & 0 deletions test/generic-pool-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,69 @@ tap.test('validate acquires object from the pool', function (t) {
})
.catch(t.threw)
})

tap.test('release to pool should work', function (t) {
const pool = createPool({
create: function () {
return Promise.resolve({ id: 'validId' })
},
validate: function (resource) {
return Promise.resolve(true)
},
destroy: function (client) {},
max: 1
})

pool.acquire()
.then(function (obj) {
t.equal(pool.available, 0)
t.equal(pool.borrowed, 1)
t.equal(pool.pending, 1)
pool.release(obj)
})
.catch(t.threw)

pool.acquire()
.then(function (obj) {
t.equal(pool.available, 0)
t.equal(pool.borrowed, 1)
t.equal(pool.pending, 0)
pool.release(obj)
utils.stopPool(pool)
t.end()
})
.catch(t.threw)
})

tap.test('destroy should redispense', function (t) {
const pool = createPool({
create: function () {
return Promise.resolve({ id: 'validId' })
},
validate: function (resource) {
return Promise.resolve(true)
},
destroy: function (client) {},
max: 1
})

pool.acquire()
.then(function (obj) {
t.equal(pool.available, 0)
t.equal(pool.borrowed, 1)
t.equal(pool.pending, 1)
pool.destroy(obj)
})
.catch(t.threw)

pool.acquire()
.then(function (obj) {
t.equal(pool.available, 0)
t.equal(pool.borrowed, 1)
t.equal(pool.pending, 0)
pool.release(obj)
utils.stopPool(pool)
t.end()
})
.catch(t.threw)
})

0 comments on commit 2ac9db9

Please sign in to comment.