From 2ced693a7db771482e1be9fa5e8490127ee0196e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 15 Oct 2022 18:53:11 +0200 Subject: [PATCH] Move worker choice strategy tests into in its own file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/cluster/fixed.test.js | 8 ------- .../selection-strategies.test.js | 23 ++++++++++++++++++- tests/pools/thread/fixed.test.js | 8 ------- 3 files changed, 22 insertions(+), 17 deletions(-) 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 -- 2.34.1