X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.js;h=d7567114ed67d35f9288bd1399c327ac6d9911f4;hb=d33be4309c69e39da5e81479e40b1a5ec7078bd5;hp=d43023b302f3923fc87218cbc8799721ca7026fc;hpb=932fc8be063cc15b543ad14c2ab6df0fa4224fba;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index d43023b3..d7567114 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -15,6 +15,7 @@ describe('Selection strategies test suite', () => { expect(WorkerChoiceStrategies.ROUND_ROBIN).toBe('ROUND_ROBIN') expect(WorkerChoiceStrategies.LEAST_USED).toBe('LEAST_USED') expect(WorkerChoiceStrategies.LEAST_BUSY).toBe('LEAST_BUSY') + expect(WorkerChoiceStrategies.LEAST_ELU).toBe('LEAST_ELU') expect(WorkerChoiceStrategies.FAIR_SHARE).toBe('FAIR_SHARE') expect(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN).toBe( 'WEIGHTED_ROUND_ROBIN' @@ -97,7 +98,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -114,7 +115,31 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) - it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => { + it('Verify ROUND_ROBIN strategy default policy', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: true + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: true + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify ROUND_ROBIN strategy default tasks statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN let pool = new FixedThreadPool( max, @@ -134,7 +159,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) await pool.destroy() pool = new DynamicThreadPool( @@ -156,7 +185,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) // We need to clean up the resources after our test await pool.destroy() @@ -195,7 +228,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) } expect( @@ -241,7 +288,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) } expect( @@ -319,7 +380,31 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) - it('Verify LEAST_USED strategy default tasks usage statistics requirements', async () => { + it('Verify LEAST_USED strategy default policy', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify LEAST_USED strategy default tasks statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED let pool = new FixedThreadPool( max, @@ -339,7 +424,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) await pool.destroy() pool = new DynamicThreadPool( @@ -361,7 +450,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) // We need to clean up the resources after our test await pool.destroy() @@ -400,7 +493,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) } // We need to clean up the resources after our test @@ -441,15 +548,52 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) } // We need to clean up the resources after our test await pool.destroy() }) - it('Verify LEAST_BUSY strategy default tasks usage statistics requirements', async () => { + it('Verify LEAST_BUSY strategy default policy', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify LEAST_BUSY strategy default tasks statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY let pool = new FixedThreadPool( max, @@ -469,7 +613,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) await pool.destroy() pool = new DynamicThreadPool( @@ -491,7 +639,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) // We need to clean up the resources after our test await pool.destroy() @@ -530,9 +682,23 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) @@ -579,7 +745,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( @@ -592,7 +772,232 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) - it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => { + it('Verify LEAST_ELU strategy default policy', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify LEAST_ELU strategy default tasks statistics requirements', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect( + pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() + ).toStrictEqual({ + runTime: { + aggregate: false, + average: false, + median: false + }, + waitTime: { + aggregate: false, + average: false, + median: false + }, + elu: { + aggregate: true, + average: false, + median: false + } + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect( + pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() + ).toStrictEqual({ + runTime: { + aggregate: false, + average: false, + median: false + }, + waitTime: { + aggregate: false, + average: false, + median: false + }, + elu: { + aggregate: true, + average: false, + median: false + } + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify LEAST_ELU strategy can be run in a fixed pool', async () => { + const pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU } + ) + // TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose` + const promises = new Set() + const maxMultiplier = 2 + for (let i = 0; i < max * maxMultiplier; i++) { + promises.add(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.workerUsage).toStrictEqual({ + tasks: { + executed: expect.any(Number), + executing: 0, + queued: 0, + failed: 0 + }, + runTime: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + waitTime: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: expect.any(Number), + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: expect.any(Number) + } + }) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) + expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) + } + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify LEAST_ELU strategy can be run in a dynamic pool', async () => { + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU } + ) + // TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose` + const promises = new Set() + const maxMultiplier = 2 + for (let i = 0; i < max * maxMultiplier; i++) { + promises.add(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.workerUsage).toStrictEqual({ + tasks: { + executed: expect.any(Number), + executing: 0, + queued: 0, + failed: 0 + }, + runTime: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + waitTime: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: expect.any(Number), + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: expect.any(Number) + } + }) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) + expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) + } + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify FAIR_SHARE strategy default policy', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: false + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify FAIR_SHARE strategy default tasks statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE let pool = new FixedThreadPool( max, @@ -612,7 +1017,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: true, + average: true, + median: false + } }) await pool.destroy() pool = new DynamicThreadPool( @@ -634,7 +1043,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: true, + average: true, + median: false + } }) // We need to clean up the resources after our test await pool.destroy() @@ -656,7 +1069,7 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.workerUsage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, failed: 0 @@ -673,10 +1086,30 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: expect.any(Number), + average: expect.any(Number), + median: 0, + history: expect.any(CircularArray) + }, + utilization: expect.any(Number) + } }) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0) + expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -704,7 +1137,7 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.workerUsage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, failed: 0 @@ -721,10 +1154,30 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: expect.any(Number), + average: expect.any(Number), + median: 0, + history: expect.any(CircularArray) + }, + utilization: expect.any(Number) + } }) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) + expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.runTime.average).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -757,7 +1210,7 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.workerUsage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, failed: 0 @@ -774,10 +1227,30 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: expect.any(Number), + average: expect.any(Number), + median: 0, + history: expect.any(CircularArray) + }, + utilization: expect.any(Number) + } }) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.workerUsage.runTime.median).toBeGreaterThan(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) + expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.runTime.median).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -862,7 +1335,31 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) - it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => { + it('Verify WEIGHTED_ROUND_ROBIN strategy default policy', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: true + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: true + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN let pool = new FixedThreadPool( max, @@ -882,7 +1379,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) await pool.destroy() pool = new DynamicThreadPool( @@ -904,7 +1405,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) // We need to clean up the resources after our test await pool.destroy() @@ -943,7 +1448,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( @@ -1000,9 +1519,23 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) @@ -1062,9 +1595,23 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) @@ -1094,7 +1641,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1110,7 +1657,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1131,7 +1678,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1147,7 +1694,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1163,7 +1710,32 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) - it('Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => { + it('Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy default policy', async () => { + const workerChoiceStrategy = + WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: true + }) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy } + ) + expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ + useDynamicWorker: true + }) + // We need to clean up the resources after our test + await pool.destroy() + }) + + it('Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy default tasks statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN let pool = new FixedThreadPool( @@ -1184,7 +1756,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) await pool.destroy() pool = new DynamicThreadPool( @@ -1206,7 +1782,11 @@ describe('Selection strategies test suite', () => { average: false, median: false }, - elu: false + elu: { + aggregate: false, + average: false, + median: false + } }) // We need to clean up the resources after our test await pool.destroy() @@ -1248,7 +1828,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) } expect( @@ -1259,12 +1853,12 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentRoundId + ).roundId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1316,7 +1910,21 @@ describe('Selection strategies test suite', () => { median: 0, history: expect.any(CircularArray) }, - elu: undefined + elu: { + idle: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + active: { + aggregate: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + utilization: 0 + } }) } expect( @@ -1327,12 +1935,12 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentRoundId + ).roundId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1357,12 +1965,12 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentRoundId + ).roundId ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1378,12 +1986,12 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentRoundId + ).roundId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1408,12 +2016,12 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentRoundId + ).roundId ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1429,7 +2037,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).currentWorkerNodeId + ).nextWorkerNodeId ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get(