X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies-utils.test.js;h=945f6ebad001426dae7d11b5635ae52c9a61c6b1;hb=d2f7b7a2e327fd754babbe16dd7ef8ff72a4a7cf;hp=dd240126392feb462f3f063bc272d942477b9886;hpb=a38092895499e2e6e9f8c45bd12bdef3849897ff;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies-utils.test.js b/tests/pools/selection-strategies/selection-strategies-utils.test.js index dd240126..945f6eba 100644 --- a/tests/pools/selection-strategies/selection-strategies-utils.test.js +++ b/tests/pools/selection-strategies/selection-strategies-utils.test.js @@ -1,5 +1,5 @@ const { expect } = require('expect') -const sinon = require('sinon') +// const sinon = require('sinon') const { SelectionStrategiesUtils } = require('../../../lib/pools/selection-strategies/selection-strategies-utils') @@ -13,15 +13,27 @@ const { const { LessRecentlyUsedWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/less-recently-used-worker-choice-strategy') +const { + FairShareWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy') +const { + WeightedRoundRobinWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') describe('Selection strategies utils test suite', () => { + const max = 3 let pool - beforeEach(() => { - pool = sinon.createStubInstance(FixedThreadPool) + + before(() => { + pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js') }) - afterEach(() => { - sinon.restore() + // afterEach(() => { + // sinon.restore() + // }) + + after(async () => { + await pool.destroy() }) it('Verify that getWorkerChoiceStrategy() default return ROUND_ROBIN strategy', () => { @@ -45,6 +57,22 @@ describe('Selection strategies utils test suite', () => { expect(strategy).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy) }) + it('Verify that getWorkerChoiceStrategy() can return FAIR_SHARE strategy', () => { + const strategy = SelectionStrategiesUtils.getWorkerChoiceStrategy( + pool, + WorkerChoiceStrategies.FAIR_SHARE + ) + expect(strategy).toBeInstanceOf(FairShareWorkerChoiceStrategy) + }) + + it('Verify that getWorkerChoiceStrategy() can return WEIGHTED_ROUND_ROBIN strategy', () => { + const strategy = SelectionStrategiesUtils.getWorkerChoiceStrategy( + pool, + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ) + expect(strategy).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) + }) + it('Verify that getWorkerChoiceStrategy() throw error on unknown strategy', () => { expect(() => { SelectionStrategiesUtils.getWorkerChoiceStrategy(pool, 'UNKNOWN_STRATEGY')