1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- "use strict";
- const tap = require("tap");
- const createPool = require("../").createPool;
- tap.test("acquireTimeout handles timed out acquire calls", function(t) {
- const factory = {
- create: function() {
- return new Promise(function(resolve) {
- setTimeout(function() {
- resolve({});
- }, 100);
- });
- },
- destroy: function() {
- return Promise.resolve();
- }
- };
- const config = {
- acquireTimeoutMillis: 20,
- idleTimeoutMillis: 150,
- log: false
- };
- const pool = createPool(factory, config);
- pool
- .acquire()
- .then(function(resource) {
- t.fail("wooops");
- })
- .catch(function(err) {
- t.match(err, /ResourceRequest timed out/);
- return pool.drain();
- })
- .then(function() {
- return pool.clear();
- })
- .then(function() {})
- .then(t.end)
- .catch(t.error);
- });
- tap.test("acquireTimeout handles non timed out acquire calls", function(t) {
- const myResource = {};
- const factory = {
- create: function() {
- return new Promise(function(resolve) {
- setTimeout(function() {
- resolve(myResource);
- }, 10);
- });
- },
- destroy: function() {
- return Promise.resolve();
- }
- };
- const config = {
- acquireTimeoutMillis: 400
- };
- const pool = createPool(factory, config);
- pool
- .acquire()
- .then(function(resource) {
- t.equal(resource, myResource);
- pool.release(resource);
- return pool.drain();
- })
- .then(function() {
- return pool.clear();
- })
- .then(t.end)
- .catch(t.error);
- });
|