X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies.test.js;h=d631afc6ed30644aa01378bf9534f7cd730ff149;hb=a7dc540979d13bee0dd320858214b776fa556e4d;hp=0c5e461155d0820fed1de17f07381a5eecb64078;hpb=b98ec2e690d5ba33a13a2848b0f1315b885c2f4b;p=poolifier.git diff --git a/tests/pools/selection-strategies.test.js b/tests/pools/selection-strategies.test.js index 0c5e4611..d631afc6 100644 --- a/tests/pools/selection-strategies.test.js +++ b/tests/pools/selection-strategies.test.js @@ -39,7 +39,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, @@ -57,6 +57,26 @@ describe('Selection strategies test suite', () => { 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() + }) + it('Verify unknown strategies throw error', () => { const min = 1 const max = 3 @@ -66,10 +86,7 @@ describe('Selection strategies test suite', () => { min, max, './tests/worker-files/thread/testWorker.js', - { - maxTasks: 1000, - workerChoiceStrategy: 'UNKNOWN_STRATEGY' - } + { workerChoiceStrategy: 'UNKNOWN_STRATEGY' } ) ).toThrowError( new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found")