X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.js;h=eedee42765e25c475310b10a07e4fb50fee097fc;hb=b6b3245344bd453ea91fa3d74acd5145f70d84fd;hp=eb30d0e17753e668ea5d9df34a8cbc734dd85210;hpb=9458090a8699203af83383930938b2a6ac53e29d;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index eb30d0e1..eedee427 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -121,15 +121,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: false, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) await pool.destroy() pool = new DynamicThreadPool( @@ -138,15 +137,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: false, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) // We need to clean up the resources after our test await pool.destroy() @@ -167,7 +165,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -177,7 +175,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) } expect( @@ -205,7 +204,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -215,7 +214,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) } expect( @@ -300,15 +300,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: false, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) await pool.destroy() pool = new DynamicThreadPool( @@ -317,15 +316,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: false, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) // We need to clean up the resources after our test await pool.destroy() @@ -346,7 +344,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -356,7 +354,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) } // We need to clean up the resources after our test @@ -379,7 +378,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -389,7 +388,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) } // We need to clean up the resources after our test @@ -403,15 +403,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: true, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) await pool.destroy() pool = new DynamicThreadPool( @@ -420,15 +419,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: true, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) // We need to clean up the resources after our test await pool.destroy() @@ -449,7 +447,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: expect.any(Number), + ran: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -459,10 +457,11 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) - expect(workerNode.tasksUsage.run).toBeGreaterThan(0) - expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier) + expect(workerNode.tasksUsage.ran).toBeGreaterThan(0) + expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) } // We need to clean up the resources after our test @@ -485,7 +484,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: expect.any(Number), + ran: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -495,10 +494,11 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) - expect(workerNode.tasksUsage.run).toBeGreaterThan(0) - expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier) + expect(workerNode.tasksUsage.ran).toBeGreaterThan(0) + expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) } // We need to clean up the resources after our test @@ -512,15 +512,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: true, avgRunTime: true, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) await pool.destroy() pool = new DynamicThreadPool( @@ -529,15 +528,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: true, avgRunTime: true, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) // We need to clean up the resources after our test await pool.destroy() @@ -558,7 +556,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -568,7 +566,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) @@ -598,7 +597,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -608,7 +607,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) @@ -643,7 +643,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -653,7 +653,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0) @@ -748,15 +749,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: true, avgRunTime: true, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) await pool.destroy() pool = new DynamicThreadPool( @@ -765,15 +765,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: true, avgRunTime: true, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) // We need to clean up the resources after our test await pool.destroy() @@ -794,7 +793,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: expect.any(Number), + ran: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -804,10 +803,11 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) - expect(workerNode.tasksUsage.run).toBeGreaterThanOrEqual(0) - expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier) + expect(workerNode.tasksUsage.ran).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier) expect(workerNode.tasksUsage.runTime).toBeGreaterThanOrEqual(0) expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) } @@ -841,7 +841,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: expect.any(Number), + ran: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -851,10 +851,11 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) - expect(workerNode.tasksUsage.run).toBeGreaterThan(0) - expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier) + expect(workerNode.tasksUsage.ran).toBeGreaterThan(0) + expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) } @@ -893,7 +894,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: expect.any(Number), + ran: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -903,10 +904,11 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) - expect(workerNode.tasksUsage.run).toBeGreaterThan(0) - expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier) + expect(workerNode.tasksUsage.ran).toBeGreaterThan(0) + expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier) expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0) } @@ -1010,15 +1012,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: false, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) await pool.destroy() pool = new DynamicThreadPool( @@ -1027,15 +1028,14 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy } ) - expect( - pool.workerChoiceStrategyContext.getRequiredStatistics() - ).toStrictEqual({ + expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({ runTime: false, avgRunTime: false, medRunTime: false, waitTime: false, avgWaitTime: false, - medWaitTime: false + medWaitTime: false, + elu: false }) // We need to clean up the resources after our test await pool.destroy() @@ -1059,7 +1059,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -1069,7 +1069,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) } expect( @@ -1119,7 +1120,7 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + ran: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -1129,7 +1130,8 @@ describe('Selection strategies test suite', () => { waitTimeHistory: expect.any(CircularArray), avgWaitTime: 0, medWaitTime: 0, - error: 0 + error: 0, + elu: undefined }) } expect( @@ -1160,6 +1162,108 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => { + const workerChoiceStrategy = + WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN + let pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js' + ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).currentRoundId + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).currentWorkerNodeId + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).defaultWorkerWeight + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundWeights + ).toBeDefined() + pool.setWorkerChoiceStrategy(workerChoiceStrategy) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).currentRoundId + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).currentWorkerNodeId + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).defaultWorkerWeight + ).toBeGreaterThan(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundWeights + ).toStrictEqual([ + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).defaultWorkerWeight + ]) + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js' + ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).currentRoundId + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).currentWorkerNodeId + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).defaultWorkerWeight + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundWeights + ).toBeDefined() + pool.setWorkerChoiceStrategy(workerChoiceStrategy) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).currentWorkerNodeId + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).defaultWorkerWeight + ).toBeGreaterThan(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundWeights + ).toStrictEqual([ + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).defaultWorkerWeight + ]) + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify unknown strategy throw error', () => { expect( () =>