X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.mjs;h=127377a26118c5d5be57cf98661eb9139fe5d81f;hb=722d55a0b7bdb6b03cc523e5debef6b612c332f8;hp=fc8a6feb65c1bf21d33b4796e9ecaecdbe3a2716;hpb=51a8af404d54403f361fe7df7f4986cacf4a6bae;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.mjs b/tests/pools/selection-strategies/selection-strategies.test.mjs index fc8a6feb..127377a2 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.mjs +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -7,6 +7,7 @@ import { WorkerChoiceStrategies } from '../../../lib/index.js' import { CircularArray } from '../../../lib/circular-array.js' +import { sleep } from '../../test-utils.js' describe('Selection strategies test suite', () => { const min = 0 @@ -174,6 +175,26 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify strategies wait for worker node readiness in dynamic pool', async () => { + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.mjs' + ) + await sleep(600) + expect(pool.starting).toBe(false) + expect(pool.workerNodes.length).toBe(min) + const maxMultiplier = 10000 + const promises = new Set() + for (let i = 0; i < max * maxMultiplier; i++) { + promises.add(pool.execute()) + } + await Promise.all(promises) + expect(pool.workerNodes.length).toBe(max) + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify ROUND_ROBIN strategy default policy', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN let pool = new FixedThreadPool( @@ -277,6 +298,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -332,6 +354,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -557,6 +580,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -615,6 +639,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -754,6 +779,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -822,6 +848,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -971,6 +998,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1045,6 +1073,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1200,6 +1229,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1285,6 +1315,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1375,6 +1406,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1575,6 +1607,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1653,6 +1686,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1736,6 +1770,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -1998,6 +2033,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 }, @@ -2083,6 +2119,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + sequentiallyStolen: 0, stolen: 0, failed: 0 },