Ali Shakiba 55417918af init
2017-01-14 02:55:26 -05:00

44 lines
840 B
JavaScript

var expect = require('./testutil/expect');
var Pool = require('../lib/util/Pool');
describe('Pool', function() {
it('Pool', function() {
var pool = new Pool({
create : function() {
return {
created : true,
busy : false,
discarded : false,
};
},
allocate : function(obj) {
obj.busy = true;
},
release : function(obj) {
obj.busy = false;
},
discard : function(obj) {
obj.discarded = true;
},
max : 1
});
var a = pool.allocate();
var b = pool.allocate();
expect(a.created).be.ok;
expect(a.busy).be.ok;
expect(a.discarded).not.be.ok;
pool.release(a);
expect(a.busy).not.be.ok;
expect(a.discarded).not.be.ok;
pool.release(b);
expect(b.discarded).be.ok;
});
});