From: Jérôme Benoit Date: Sat, 15 Oct 2022 16:53:11 +0000 (+0200) Subject: Move worker choice strategy tests into in its own file X-Git-Tag: v2.3.4~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2ced693a7db771482e1be9fa5e8490127ee0196e;p=poolifier.git Move worker choice strategy tests into in its own file Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index e00e5fa3..b0e39c30 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -49,14 +49,6 @@ describe('Fixed cluster pool test suite', () => { await emptyPool.destroy() }) - it('Choose worker round robin test', async () => { - const results = new Set() - for (let i = 0; i < numberOfWorkers; i++) { - results.add(pool.chooseWorker().id) - } - expect(results.size).toBe(numberOfWorkers) - }) - it('Verify that the function is executed in a worker cluster', async () => { let result = await pool.execute({ function: WorkerFunctions.fibonacci diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index b8341f09..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, diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index a0fd08c8..116a17da 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -49,14 +49,6 @@ describe('Fixed thread pool test suite', () => { await emptyPool.destroy() }) - it('Choose worker round robin test', async () => { - const results = new Set() - for (let i = 0; i < numberOfThreads; i++) { - results.add(pool.chooseWorker().threadId) - } - expect(results.size).toBe(numberOfThreads) - }) - it('Verify that the function is executed in a worker thread', async () => { let result = await pool.execute({ function: WorkerFunctions.fibonacci