test: remove commented out code
[poolifier.git] / tests / pools / utils.test.mjs
index c6cc06d31487f2b492850203fb64ceda79d2ae87..f29515d516bf4fc8250083afda6795af6aa3ac0f 100644 (file)
@@ -3,25 +3,17 @@ import { Worker as ThreadWorker } from 'node:worker_threads'
 
 import { expect } from 'expect'
 
+import { CircularBuffer } from '../../lib/circular-buffer.cjs'
+import { WorkerTypes } from '../../lib/index.cjs'
 import {
-  CircularArray,
-  DEFAULT_CIRCULAR_ARRAY_SIZE
-} from '../../lib/circular-array.cjs'
-import {
-  FixedClusterPool,
-  FixedThreadPool,
-  WorkerTypes
-} from '../../lib/index.cjs'
-import {
-  buildWorkerChoiceStrategyOptions,
   createWorker,
   DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
   getDefaultTasksQueueOptions,
-  getWorkerChoiceStrategyRetries,
   getWorkerId,
   getWorkerType,
   updateMeasurementStatistics
 } from '../../lib/pools/utils.cjs'
+import { MeasurementHistorySize } from '../../lib/pools/worker.cjs'
 
 describe('Pool utils test suite', () => {
   it('Verify DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS values', () => {
@@ -38,150 +30,78 @@ describe('Pool utils test suite', () => {
       concurrency: 1,
       size: Math.pow(poolMaxSize, 2),
       taskStealing: true,
-      tasksStealingOnBackPressure: true,
+      tasksStealingOnBackPressure: false,
       tasksFinishedTimeout: 2000
     })
   })
 
-  it('Verify getWorkerChoiceStrategyRetries() behavior', async () => {
-    const numberOfThreads = 4
-    const pool = new FixedThreadPool(
-      numberOfThreads,
-      './tests/worker-files/thread/testWorker.mjs'
-    )
-    expect(getWorkerChoiceStrategyRetries(pool)).toBe(pool.info.maxSize * 2)
-    const workerChoiceStrategyOptions = {
-      runTime: { median: true },
-      waitTime: { median: true },
-      elu: { median: true },
-      weights: {
-        0: 100,
-        1: 100
-      }
-    }
-    expect(
-      getWorkerChoiceStrategyRetries(pool, workerChoiceStrategyOptions)
-    ).toBe(
-      pool.info.maxSize +
-        Object.keys(workerChoiceStrategyOptions.weights).length
-    )
-    await pool.destroy()
-  })
-
-  it('Verify buildWorkerChoiceStrategyOptions() behavior', async () => {
-    const numberOfWorkers = 4
-    const pool = new FixedClusterPool(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.cjs'
-    )
-    expect(buildWorkerChoiceStrategyOptions(pool)).toStrictEqual({
-      runTime: { median: false },
-      waitTime: { median: false },
-      elu: { median: false },
-      weights: expect.objectContaining({
-        0: expect.any(Number),
-        [pool.info.maxSize - 1]: expect.any(Number)
-      })
-    })
-    const workerChoiceStrategyOptions = {
-      runTime: { median: true },
-      waitTime: { median: true },
-      elu: { median: true },
-      weights: {
-        0: 100,
-        1: 100
-      }
-    }
-    expect(
-      buildWorkerChoiceStrategyOptions(pool, workerChoiceStrategyOptions)
-    ).toStrictEqual(workerChoiceStrategyOptions)
-    await pool.destroy()
-  })
-
   it('Verify updateMeasurementStatistics() behavior', () => {
     const measurementStatistics = {
-      history: new CircularArray()
+      history: new CircularBuffer(MeasurementHistorySize)
     }
     updateMeasurementStatistics(
       measurementStatistics,
       { aggregate: true, average: false, median: false },
       0.01
     )
-    expect(measurementStatistics).toStrictEqual({
+    expect(measurementStatistics).toMatchObject({
       aggregate: 0.01,
       maximum: 0.01,
-      minimum: 0.01,
-      history: new CircularArray()
+      minimum: 0.01
     })
     updateMeasurementStatistics(
       measurementStatistics,
       { aggregate: true, average: false, median: false },
       0.02
     )
-    expect(measurementStatistics).toStrictEqual({
+    expect(measurementStatistics).toMatchObject({
       aggregate: 0.03,
       maximum: 0.02,
-      minimum: 0.01,
-      history: new CircularArray()
+      minimum: 0.01
     })
     updateMeasurementStatistics(
       measurementStatistics,
       { aggregate: true, average: true, median: false },
       0.001
     )
-    expect(measurementStatistics).toStrictEqual({
+    expect(measurementStatistics).toMatchObject({
       aggregate: 0.031,
       maximum: 0.02,
       minimum: 0.001,
-      average: 0.001,
-      history: new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, 0.001)
+      average: 0.0010000000474974513
     })
     updateMeasurementStatistics(
       measurementStatistics,
       { aggregate: true, average: true, median: false },
       0.003
     )
-    expect(measurementStatistics).toStrictEqual({
+    expect(measurementStatistics).toMatchObject({
       aggregate: 0.034,
       maximum: 0.02,
       minimum: 0.001,
-      average: 0.002,
-      history: new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, 0.001, 0.003)
+      average: 0.0020000000367872417
     })
     updateMeasurementStatistics(
       measurementStatistics,
       { aggregate: true, average: false, median: true },
       0.006
     )
-    expect(measurementStatistics).toStrictEqual({
+    expect(measurementStatistics).toMatchObject({
       aggregate: 0.04,
       maximum: 0.02,
       minimum: 0.001,
-      median: 0.003,
-      history: new CircularArray(
-        DEFAULT_CIRCULAR_ARRAY_SIZE,
-        0.001,
-        0.003,
-        0.006
-      )
+      median: 0.003000000026077032
     })
     updateMeasurementStatistics(
       measurementStatistics,
       { aggregate: true, average: true, median: false },
       0.01
     )
-    expect(measurementStatistics).toStrictEqual({
+    expect(measurementStatistics).toMatchObject({
       aggregate: 0.05,
       maximum: 0.02,
       minimum: 0.001,
-      average: 0.005,
-      history: new CircularArray(
-        DEFAULT_CIRCULAR_ARRAY_SIZE,
-        0.001,
-        0.003,
-        0.006,
-        0.01
-      )
+      average: 0.004999999975552782
     })
   })