X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.mjs;h=bca3c82b1647e22146b6094321d7c9ac60485403;hb=6df7fd58278efabaca36bc515ba038ebcae807ec;hp=4a2ace0469d1da108fe49e3c5f776ab3ad8a5825;hpb=463226a44b0370911db746052bcad0bcc7878acf;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.mjs b/tests/pools/selection-strategies/selection-strategies.test.mjs index 4a2ace04..bca3c82b 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.mjs +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -5,8 +5,8 @@ import { FixedClusterPool, FixedThreadPool, WorkerChoiceStrategies -} from '../../../lib/index.js' -import { CircularArray } from '../../../lib/circular-array.js' +} from '../../../lib/index.cjs' +import { CircularArray } from '../../../lib/circular-array.cjs' describe('Selection strategies test suite', () => { const min = 0 @@ -66,43 +66,19 @@ describe('Selection strategies test suite', () => { expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) - expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ - retries: 6, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } - }) - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: 6, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } - }) await pool.destroy() } for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { const pool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) - pool.setWorkerChoiceStrategy(workerChoiceStrategy, { retries: 3 }) + pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy) expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) - expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ - retries: 3, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } - }) - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: 3, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } - }) await pool.destroy() } }) @@ -126,11 +102,6 @@ describe('Selection strategies test suite', () => { if ( workerChoiceStrategy === WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) { - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -140,11 +111,6 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy === WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN ) { - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -163,12 +129,15 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).roundWeights - ).toStrictEqual([ - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ]) + ).roundWeights.length + ).toBe(1) + expect( + Number.isSafeInteger( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundWeights[0] + ) + ).toBe(true) } } await pool.destroy() @@ -277,8 +246,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: { @@ -333,8 +302,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: { @@ -375,7 +344,7 @@ describe('Selection strategies test suite', () => { const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN let pool = new FixedClusterPool( max, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { workerChoiceStrategy } ) let results = new Set() @@ -559,8 +528,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: { @@ -618,8 +587,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: { @@ -758,8 +727,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -827,8 +796,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -977,8 +946,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: { @@ -1052,8 +1021,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: { @@ -1208,8 +1177,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1294,8 +1263,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1385,8 +1354,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1586,8 +1555,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1629,12 +1598,7 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey - ).toBe(0) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1665,8 +1629,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1703,17 +1667,12 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey - ).toBe(0) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey - ).toBe(0) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1749,8 +1708,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1787,17 +1746,12 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey - ).toBe(0) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey - ).toBe(0) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1823,11 +1777,6 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).previousWorkerNodeKey ).toBeDefined() - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -1844,11 +1793,6 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey ).toBe(0) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1870,11 +1814,6 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).previousWorkerNodeKey ).toBeDefined() - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -1891,11 +1830,6 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey ).toBe(0) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -2012,8 +1946,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -2036,11 +1970,6 @@ describe('Selection strategies test suite', () => { max * maxMultiplier ) } - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -2060,16 +1989,19 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey - ).toEqual(expect.any(Number)) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).roundWeights - ).toStrictEqual([ - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ]) + ).roundWeights.length + ).toBe(1) + expect( + Number.isSafeInteger( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).roundWeights[0] + ) + ).toBe(true) // We need to clean up the resources after our test await pool.destroy() }) @@ -2098,8 +2030,8 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, - stolen: 0, sequentiallyStolen: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -2122,11 +2054,6 @@ describe('Selection strategies test suite', () => { max * maxMultiplier ) } - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -2146,16 +2073,19 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).previousWorkerNodeKey - ).toEqual(expect.any(Number)) + ).toEqual(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).roundWeights - ).toStrictEqual([ - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ]) + ).roundWeights.length + ).toBe(1) + expect( + Number.isSafeInteger( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).roundWeights[0] + ) + ).toBe(true) // We need to clean up the resources after our test await pool.destroy() }) @@ -2187,11 +2117,6 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).previousWorkerNodeKey ).toBeDefined() - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -2221,17 +2146,15 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) + ).roundWeights.length + ).toBe(1) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).roundWeights - ).toStrictEqual([ - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ]) + Number.isSafeInteger( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).roundWeights[0] + ) + ).toBe(true) await pool.destroy() pool = new DynamicThreadPool( min, @@ -2258,11 +2181,6 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).previousWorkerNodeKey ).toBeDefined() - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).defaultWorkerWeight - ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -2292,17 +2210,15 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ).toBeGreaterThan(0) + ).roundWeights.length + ).toBe(1) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).roundWeights - ).toStrictEqual([ - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).defaultWorkerWeight - ]) + Number.isSafeInteger( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).roundWeights[0] + ) + ).toBe(true) // We need to clean up the resources after our test await pool.destroy() })