X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.js;h=3329e1dc718f3565202e1344479248013a6171c8;hb=50b332ec235604105c6290eee79d16ab5757eac1;hp=daa1b4e73f67726d01b074c3064a65a5c0d06f6a;hpb=516dcb0df1957823ec30f15db5f7585a7a302e8f;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index daa1b4e7..3329e1dc 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -123,18 +123,7 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).previousWorkerNodeKey ).toBe(0) - if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp - ).toBeInstanceOf(Array) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(0) - } else if ( + if ( workerChoiceStrategy === WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) { expect( @@ -145,7 +134,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBe(0) } else if ( workerChoiceStrategy === @@ -159,7 +148,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -413,6 +402,16 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -431,6 +430,16 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -571,6 +580,16 @@ describe('Selection strategies test suite', () => { max * maxMultiplier ) } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -619,6 +638,16 @@ describe('Selection strategies test suite', () => { max * maxMultiplier ) } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -758,6 +787,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0) } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -816,6 +855,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0) } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -961,6 +1010,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -1025,6 +1084,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -1179,12 +1248,18 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } + expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(pool.workerNodes.length) + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -1258,12 +1333,18 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } + expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(pool.workerNodes.length) + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -1342,12 +1423,18 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } + expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(pool.workerNodes.length) + ).nextWorkerNodeKey + ).toEqual(expect.any(Number)) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) // We need to clean up the resources after our test await pool.destroy() }) @@ -1358,70 +1445,30 @@ describe('Selection strategies test suite', () => { max, './tests/worker-files/thread/testWorker.js' ) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp - ).toBeInstanceOf(Array) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(0) - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp[0] = performance.now() - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(1) + for (const workerNode of pool.workerNodes) { + workerNode.strategyData = { + virtualTaskEndTimestamp: performance.now() + } + } pool.setWorkerChoiceStrategy(workerChoiceStrategy) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp - ).toBeInstanceOf(Array) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(0) + for (const workerNode of pool.workerNodes) { + expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeUndefined() + } await pool.destroy() pool = new DynamicThreadPool( min, max, './tests/worker-files/thread/testWorker.js' ) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp - ).toBeInstanceOf(Array) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(0) - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp[0] = performance.now() - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(1) + for (const workerNode of pool.workerNodes) { + workerNode.strategyData = { + virtualTaskEndTimestamp: performance.now() + } + } pool.setWorkerChoiceStrategy(workerChoiceStrategy) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp - ).toBeInstanceOf(Array) - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workersVirtualTaskEndTimestamp.length - ).toBe(0) + for (const workerNode of pool.workerNodes) { + expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeUndefined() + } // We need to clean up the resources after our test await pool.destroy() }) @@ -1579,7 +1626,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBeGreaterThanOrEqual(0) // We need to clean up the resources after our test await pool.destroy() @@ -1657,7 +1704,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBeGreaterThanOrEqual(0) // We need to clean up the resources after our test await pool.destroy() @@ -1740,7 +1787,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBeGreaterThanOrEqual(0) // We need to clean up the resources after our test await pool.destroy() @@ -1770,7 +1817,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( @@ -1791,7 +1838,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBe(0) await pool.destroy() pool = new DynamicThreadPool( @@ -1817,7 +1864,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( @@ -1838,7 +1885,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).workerVirtualTaskRunTime + ).workerNodeVirtualTaskRunTime ).toBe(0) // We need to clean up the resources after our test await pool.destroy()