X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.js;h=93d85ea6e419e52a1d3e861f18b485ea688fd580;hb=2ced693a7db771482e1be9fa5e8490127ee0196e;hp=64b26cd54c15426a61f857fe068f7466d11c814d;hpb=38f6e859ac08e5bed3ced3b7940d02de517a1f76;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 64b26cd5..93d85ea6 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -2,7 +2,8 @@ const { expect } = require('expect') const { WorkerChoiceStrategies, DynamicThreadPool, - FixedThreadPool + FixedThreadPool, + FixedClusterPool } = require('../../../lib/index') describe('Selection strategies test suite', () => { @@ -125,6 +126,26 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify ROUND_ROBIN strategy runtime behavior', async () => { + let pool = new FixedClusterPool( + max, + './tests/worker-files/cluster/testWorker.js' + ) + let results = new Set() + for (let i = 0; i < max; i++) { + results.add(pool.chooseWorker().id) + } + expect(results.size).toBe(max) + await pool.destroy() + pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js') + results = new Set() + for (let i = 0; i < max; i++) { + results.add(pool.chooseWorker().threadId) + } + expect(results.size).toBe(max) + await pool.destroy() + }) + it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => { let pool = new FixedThreadPool( max, @@ -402,10 +423,6 @@ describe('Selection strategies test suite', () => { expect(pool.opts.workerChoiceStrategy).toBe( WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) - expect( - pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() - .previousWorkerIndex - ).toBe(0) expect( pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() .currentWorkerIndex @@ -508,10 +525,6 @@ describe('Selection strategies test suite', () => { max, './tests/worker-files/thread/testWorker.js' ) - expect( - pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() - .previousWorkerIndex - ).toBeUndefined() expect( pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() .currentWorkerIndex @@ -525,10 +538,6 @@ describe('Selection strategies test suite', () => { .workersTaskRunTime ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) - expect( - pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() - .previousWorkerIndex - ).toBe(0) expect( pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() .currentWorkerIndex @@ -552,10 +561,6 @@ describe('Selection strategies test suite', () => { max, './tests/worker-files/thread/testWorker.js' ) - expect( - pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() - .workerChoiceStrategy.previousWorkerIndex - ).toBeUndefined() expect( pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() .workerChoiceStrategy.currentWorkerIndex @@ -569,10 +574,6 @@ describe('Selection strategies test suite', () => { .workerChoiceStrategy.workersTaskRunTime ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) - expect( - pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() - .workerChoiceStrategy.previousWorkerIndex - ).toBe(0) expect( pool.workerChoiceStrategyContext.getWorkerChoiceStrategy() .workerChoiceStrategy.currentWorkerIndex