X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies.test.js;h=f57eaed2c1caec6d2b1002fb8b26224fd4dde6bb;hb=e843b9042b77e0e4e17c193820a3e05ffc92cffe;hp=604dda3d52f9ed46165e8943d145b4bc99c1e8e0;hpb=1927ee6758147bb8a2479b987322564cea20992b;p=poolifier.git diff --git a/tests/pools/selection-strategies.test.js b/tests/pools/selection-strategies.test.js index 604dda3d..f57eaed2 100644 --- a/tests/pools/selection-strategies.test.js +++ b/tests/pools/selection-strategies.test.js @@ -11,6 +11,37 @@ describe('Selection strategies test suite', () => { expect(WorkerChoiceStrategies.LESS_RECENTLY_USED).toBe('LESS_RECENTLY_USED') }) + it('Verify ROUND_ROBIN strategy is the default at pool creation', async () => { + const min = 0 + const max = 3 + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js' + ) + expect(pool.opts.workerChoiceStrategy).toBe( + WorkerChoiceStrategies.ROUND_ROBIN + ) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify ROUND_ROBIN strategy can be set after pool creation', async () => { + const min = 0 + const max = 3 + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js' + ) + pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN) + expect(pool.opts.workerChoiceStrategy).toBe( + WorkerChoiceStrategies.ROUND_ROBIN + ) + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify LESS_RECENTLY_USED strategy is taken at pool creation', async () => { const max = 3 const pool = new FixedThreadPool( @@ -39,7 +70,7 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) - it('Verify LESS_RECENTLY_USED strategy can be run in a pool', async () => { + it('Verify LESS_RECENTLY_USED strategy can be run in a fixed pool', async () => { const max = 3 const pool = new FixedThreadPool( max, @@ -52,7 +83,25 @@ describe('Selection strategies test suite', () => { promises.push(pool.execute({ test: 'test' })) } await Promise.all(promises) + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify LESS_RECENTLY_USED strategy can be run in a dynamic pool', async () => { + const min = 0 + const max = 3 + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED } + ) + // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose` + const promises = [] + for (let i = 0; i < max * 2; i++) { + promises.push(pool.execute({ test: 'test' })) + } + await Promise.all(promises) // We need to clean up the resources after our test await pool.destroy() })