pool.test.js 893 B

1234567891011121314151617181920212223242526272829
  1. import { Pool } from "../pool";
  2. var m = jest.fn();
  3. var task = function () {
  4. return new Promise(function (resolve, _) {
  5. m();
  6. resolve();
  7. });
  8. };
  9. describe("test Pool for control concurrency", function () {
  10. var pool = new Pool(task, 2);
  11. test("pool.js", function () {
  12. var chunk = new Blob();
  13. var data = [
  14. { chunk: chunk, index: 0 },
  15. { chunk: chunk, index: 1 },
  16. { chunk: chunk, index: 2 },
  17. { chunk: chunk, index: 3 },
  18. { chunk: chunk, index: 4 },
  19. { chunk: chunk, index: 5 }
  20. ];
  21. return Promise.all(data.map(function (value) {
  22. pool.enqueue(value);
  23. expect(pool.processing.length).toBeLessThanOrEqual(2);
  24. })).then(function () {
  25. expect(m.mock.calls.length).toBe(6);
  26. });
  27. });
  28. });
  29. //# sourceMappingURL=pool.test.js.map