diff --git a/src/Pool.ts b/src/Pool.ts index 6bd30d2..21937ba 100644 --- a/src/Pool.ts +++ b/src/Pool.ts @@ -442,6 +442,15 @@ export class Pool { this._pendingAcquires.push(deferred); this._dispense(); + let i, diff; + if (this.size < this.minSize) { + diff = this.minSize - this.size; + for (i = 0; i < diff; i++) { + this._pendingAcquires.push(deferred); + this._dispense(); + } + } + return deferred.promise(); } diff --git a/test/integration/pool-test.js b/test/integration/pool-test.js index 82f048f..eaba22b 100644 --- a/test/integration/pool-test.js +++ b/test/integration/pool-test.js @@ -31,6 +31,31 @@ tap.test('pool expands only to max limit', (t) => { .catch(t.threw); }); +tap.test('pool expands to min', (t) => { + const resourceFactory = new ResourceFactory(); + + const factory = { + name: 'test1', + create: resourceFactory.create.bind(resourceFactory), + destroy: resourceFactory.destroy.bind(resourceFactory), + validate: resourceFactory.validate.bind(resourceFactory), + max: 3, + min: 2, + idleTimeoutMillis: 100, + acquireTimeoutMillis: 100, + }; + + const pool = new Pool(factory); + + pool + .acquire() + .then((client) => { + t.equal(2, pool.using); + t.end(); + }) + .catch(t.threw); +}); + tap.test('pool uses LIFO', (t) => { const resourceFactory = new ResourceFactory();