utils.js 749 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. const Pool = require("../lib/Pool");
  3. /**
  4. * Generic class for handling creation of resources
  5. * for testing
  6. */
  7. class ResourceFactory {
  8. constructor() {
  9. this.created = 0;
  10. this.destroyed = 0;
  11. this.bin = [];
  12. }
  13. create() {
  14. return Promise.resolve({ id: this.created++ });
  15. }
  16. validate() {
  17. return Promise.resolve(true);
  18. }
  19. destroy(resource) {
  20. this.destroyed++;
  21. this.bin.push(resource);
  22. return Promise.resolve();
  23. }
  24. }
  25. exports.ResourceFactory = ResourceFactory;
  26. /**
  27. * drains and terminates the pool
  28. *
  29. * @param {Pool} pool [description]
  30. * @return {Promise} [description]
  31. */
  32. exports.stopPool = function(pool) {
  33. return pool.drain().then(function() {
  34. return pool.clear();
  35. });
  36. };