histogram.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Piscina from '..';
  2. import { test } from 'tap';
  3. import { resolve } from 'path';
  4. test('pool will maintain run and wait time histograms by default', async ({ equal, ok }) => {
  5. const pool = new Piscina({
  6. filename: resolve(__dirname, 'fixtures/eval.js')
  7. });
  8. const tasks = [];
  9. for (let n = 0; n < 10; n++) {
  10. tasks.push(pool.runTask('42'));
  11. }
  12. await Promise.all(tasks);
  13. const waitTime = pool.waitTime as any;
  14. ok(waitTime);
  15. equal(typeof waitTime.average, 'number');
  16. equal(typeof waitTime.mean, 'number');
  17. equal(typeof waitTime.stddev, 'number');
  18. equal(typeof waitTime.min, 'number');
  19. equal(typeof waitTime.max, 'number');
  20. const runTime = pool.runTime as any;
  21. ok(runTime);
  22. equal(typeof runTime.average, 'number');
  23. equal(typeof runTime.mean, 'number');
  24. equal(typeof runTime.stddev, 'number');
  25. equal(typeof runTime.min, 'number');
  26. equal(typeof runTime.max, 'number');
  27. });
  28. test('pool will maintain run and wait time histograms when recordTiming is true', async ({ ok }) => {
  29. const pool = new Piscina({
  30. filename: resolve(__dirname, 'fixtures/eval.js'),
  31. recordTiming: true
  32. });
  33. const tasks = [];
  34. for (let n = 0; n < 10; n++) {
  35. tasks.push(pool.runTask('42'));
  36. }
  37. await Promise.all(tasks);
  38. const waitTime = pool.waitTime as any;
  39. ok(waitTime);
  40. const runTime = pool.runTime as any;
  41. ok(runTime);
  42. });
  43. test('pool does not maintain run and wait time histograms when recordTiming is false', async ({ equal }) => {
  44. const pool = new Piscina({
  45. filename: resolve(__dirname, 'fixtures/eval.js'),
  46. recordTiming: false
  47. });
  48. const tasks = [];
  49. for (let n = 0; n < 10; n++) {
  50. tasks.push(pool.runTask('42'));
  51. }
  52. await Promise.all(tasks);
  53. equal(pool.waitTime, null);
  54. equal(pool.runTime, null);
  55. });