You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
749 B
43 lines
749 B
3 years ago
|
"use strict";
|
||
|
|
||
|
const Pool = require("../lib/Pool");
|
||
|
|
||
|
/**
|
||
|
* Generic class for handling creation of resources
|
||
|
* for testing
|
||
|
*/
|
||
|
class ResourceFactory {
|
||
|
constructor() {
|
||
|
this.created = 0;
|
||
|
this.destroyed = 0;
|
||
|
this.bin = [];
|
||
|
}
|
||
|
|
||
|
create() {
|
||
|
return Promise.resolve({ id: this.created++ });
|
||
|
}
|
||
|
|
||
|
validate() {
|
||
|
return Promise.resolve(true);
|
||
|
}
|
||
|
|
||
|
destroy(resource) {
|
||
|
this.destroyed++;
|
||
|
this.bin.push(resource);
|
||
|
return Promise.resolve();
|
||
|
}
|
||
|
}
|
||
|
exports.ResourceFactory = ResourceFactory;
|
||
|
|
||
|
/**
|
||
|
* drains and terminates the pool
|
||
|
*
|
||
|
* @param {Pool} pool [description]
|
||
|
* @return {Promise} [description]
|
||
|
*/
|
||
|
exports.stopPool = function(pool) {
|
||
|
return pool.drain().then(function() {
|
||
|
return pool.clear();
|
||
|
});
|
||
|
};
|