X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.js;h=055a2dbb64e6257bef21221f709c2e0756b89d84;hb=86ed05989a886c9e44d5be0089d5381debfb2294;hp=6671b57781b1f51c15bdf0717f3c96cafcf0ca76;hpb=3d6dd312a7825521cce506ebb7443bae36a111e6;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 6671b577..055a2dbb 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -1,5 +1,6 @@ const { expect } = require('expect') const { + DynamicClusterPool, DynamicThreadPool, FixedClusterPool, FixedThreadPool, @@ -65,6 +66,43 @@ describe('Selection strategies test suite', () => { expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) + expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ + retries: 6, + runTime: { median: false }, + waitTime: { median: false }, + elu: { median: false } + }) + expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ + retries: 6, + runTime: { median: false }, + waitTime: { median: false }, + elu: { median: false } + }) + await pool.destroy() + } + for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { + const pool = new DynamicClusterPool( + min, + max, + './tests/worker-files/cluster/testWorker.js' + ) + pool.setWorkerChoiceStrategy(workerChoiceStrategy, { retries: 3 }) + expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy) + expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe( + workerChoiceStrategy + ) + expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ + retries: 3, + runTime: { median: false }, + waitTime: { median: false }, + elu: { median: false } + }) + expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ + retries: 3, + runTime: { median: false }, + waitTime: { median: false }, + elu: { median: false } + }) await pool.destroy() } }) @@ -75,13 +113,17 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js' ) for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { - if (workerChoiceStrategy === WorkerChoiceStrategies.ROUND_ROBIN) { - expect( - pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).nextWorkerNodeKey - ).toBe(0) - } else if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).nextWorkerNodeKey + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) + if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -98,8 +140,17 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeKey + ).defaultWorkerWeight + ).toBeGreaterThan(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).workerVirtualTaskRunTime ).toBe(0) + } else if ( + workerChoiceStrategy === + WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN + ) { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -110,6 +161,25 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).workerVirtualTaskRunTime ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundId + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).workerNodeId + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).roundWeights + ).toStrictEqual([ + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).defaultWorkerWeight + ]) } } await pool.destroy() @@ -123,7 +193,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -133,7 +204,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -196,10 +268,11 @@ describe('Selection strategies test suite', () => { }) it('Verify ROUND_ROBIN strategy can be run in a fixed pool', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN const pool = new FixedThreadPool( max, './tests/worker-files/thread/testWorker.js', - { workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN } + { workerChoiceStrategy } ) // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose` const promises = new Set() @@ -215,39 +288,46 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - WorkerChoiceStrategies.ROUND_ROBIN + pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(pool.workerNodes.length - 1) // We need to clean up the resources after our test await pool.destroy() }) it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => { + const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN const pool = new DynamicThreadPool( min, max, './tests/worker-files/thread/testWorker.js', - { workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN } + { workerChoiceStrategy } ) // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose` const promises = new Set() @@ -259,33 +339,43 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.usage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - WorkerChoiceStrategies.ROUND_ROBIN + pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(pool.workerNodes.length - 1) // We need to clean up the resources after our test await pool.destroy() }) @@ -325,15 +415,25 @@ describe('Selection strategies test suite', () => { ) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) await pool.destroy() pool = new DynamicThreadPool( min, @@ -343,15 +443,25 @@ describe('Selection strategies test suite', () => { ) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) // We need to clean up the resources after our test await pool.destroy() }) @@ -364,7 +474,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -374,7 +485,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -456,20 +568,21 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -503,20 +616,21 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -537,7 +651,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -547,7 +662,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -623,26 +739,27 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: { + runTime: expect.objectContaining({ history: expect.any(CircularArray) - }, - waitTime: { + }), + waitTime: expect.objectContaining({ history: expect.any(CircularArray) - }, + }), elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -680,26 +797,27 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: { + runTime: expect.objectContaining({ history: expect.any(CircularArray) - }, - waitTime: { + }), + waitTime: expect.objectContaining({ history: expect.any(CircularArray) - }, + }), elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -730,7 +848,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -740,7 +859,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -816,33 +936,44 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, - elu: { + elu: expect.objectContaining({ idle: expect.objectContaining({ history: expect.any(CircularArray) }), active: expect.objectContaining({ history: expect.any(CircularArray) }) - } + }) }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) + if (workerNode.usage.elu.active.aggregate == null) { + expect(workerNode.usage.elu.active.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.elu.idle.aggregate == null) { + expect(workerNode.usage.elu.idle.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0) + } if (workerNode.usage.elu.utilization == null) { expect(workerNode.usage.elu.utilization).toBeUndefined() } else { @@ -869,33 +1000,44 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, - elu: { + elu: expect.objectContaining({ idle: expect.objectContaining({ history: expect.any(CircularArray) }), active: expect.objectContaining({ history: expect.any(CircularArray) }) - } + }) }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) + if (workerNode.usage.elu.active.aggregate == null) { + expect(workerNode.usage.elu.active.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.elu.idle.aggregate == null) { + expect(workerNode.usage.elu.idle.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0) + } if (workerNode.usage.elu.utilization == null) { expect(workerNode.usage.elu.utilization).toBeUndefined() } else { @@ -915,7 +1057,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -925,7 +1068,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -1001,28 +1145,29 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ history: expect.any(CircularArray) }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, - elu: { + elu: expect.objectContaining({ idle: expect.objectContaining({ history: expect.any(CircularArray) }), active: expect.objectContaining({ history: expect.any(CircularArray) }) - } + }) }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( @@ -1038,6 +1183,16 @@ describe('Selection strategies test suite', () => { } else { expect(workerNode.usage.runTime.average).toBeGreaterThan(0) } + if (workerNode.usage.elu.active.aggregate == null) { + expect(workerNode.usage.elu.active.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.elu.idle.aggregate == null) { + expect(workerNode.usage.elu.idle.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0) + } if (workerNode.usage.elu.utilization == null) { expect(workerNode.usage.elu.utilization).toBeUndefined() } else { @@ -1069,28 +1224,29 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ history: expect.any(CircularArray) }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, - elu: { + elu: expect.objectContaining({ idle: expect.objectContaining({ history: expect.any(CircularArray) }), active: expect.objectContaining({ history: expect.any(CircularArray) }) - } + }) }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( @@ -1106,6 +1262,16 @@ describe('Selection strategies test suite', () => { } else { expect(workerNode.usage.runTime.average).toBeGreaterThan(0) } + if (workerNode.usage.elu.active.aggregate == null) { + expect(workerNode.usage.elu.active.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.elu.idle.aggregate == null) { + expect(workerNode.usage.elu.idle.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0) + } if (workerNode.usage.elu.utilization == null) { expect(workerNode.usage.elu.utilization).toBeUndefined() } else { @@ -1142,28 +1308,29 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toMatchObject({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ history: expect.any(CircularArray) }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, - elu: { + elu: expect.objectContaining({ idle: expect.objectContaining({ history: expect.any(CircularArray) }), active: expect.objectContaining({ history: expect.any(CircularArray) }) - } + }) }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( @@ -1179,6 +1346,16 @@ describe('Selection strategies test suite', () => { } else { expect(workerNode.usage.runTime.median).toBeGreaterThan(0) } + if (workerNode.usage.elu.active.aggregate == null) { + expect(workerNode.usage.elu.active.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.elu.idle.aggregate == null) { + expect(workerNode.usage.elu.idle.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0) + } if (workerNode.usage.elu.utilization == null) { expect(workerNode.usage.elu.utilization).toBeUndefined() } else { @@ -1222,12 +1399,12 @@ describe('Selection strategies test suite', () => { pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).workersVirtualTaskEndTimestamp ).toBeInstanceOf(Array) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).workersVirtualTaskEndTimestamp.length ).toBe(0) await pool.destroy() @@ -1257,12 +1434,12 @@ describe('Selection strategies test suite', () => { pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).workersVirtualTaskEndTimestamp ).toBeInstanceOf(Array) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).workersVirtualTaskEndTimestamp.length ).toBe(0) // We need to clean up the resources after our test @@ -1277,7 +1454,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -1287,7 +1465,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -1369,20 +1548,21 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ history: expect.any(CircularArray) }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -1401,6 +1581,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.runTime.average).toBeGreaterThan(0) } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1436,24 +1626,21 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: { - aggregate: expect.any(Number), - maximum: expect.any(Number), - minimum: expect.any(Number), - average: expect.any(Number), + runTime: expect.objectContaining({ history: expect.any(CircularArray) - }, + }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -1461,9 +1648,27 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.usage.runTime.average).toBeGreaterThan(0) + if (workerNode.usage.runTime.aggregate == null) { + expect(workerNode.usage.runTime.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.runTime.average == null) { + expect(workerNode.usage.runTime.average).toBeUndefined() + } else { + expect(workerNode.usage.runTime.average).toBeGreaterThan(0) + } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1504,24 +1709,21 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: { - aggregate: expect.any(Number), - maximum: expect.any(Number), - minimum: expect.any(Number), - median: expect.any(Number), + runTime: expect.objectContaining({ history: expect.any(CircularArray) - }, + }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) @@ -1529,9 +1731,27 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.usage.runTime.median).toBeGreaterThan(0) + if (workerNode.usage.runTime.aggregate == null) { + expect(workerNode.usage.runTime.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.runTime.median == null) { + expect(workerNode.usage.runTime.median).toBeUndefined() + } else { + expect(workerNode.usage.runTime.median).toBeGreaterThan(0) + } } + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1557,6 +1777,11 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).nextWorkerNodeKey ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -1573,6 +1798,11 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1580,7 +1810,7 @@ describe('Selection strategies test suite', () => { ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).workerVirtualTaskRunTime ).toBe(0) await pool.destroy() @@ -1594,6 +1824,11 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).nextWorkerNodeKey ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -1610,6 +1845,11 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1617,7 +1857,7 @@ describe('Selection strategies test suite', () => { ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).workerVirtualTaskRunTime ).toBe(0) // We need to clean up the resources after our test @@ -1633,7 +1873,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -1643,7 +1884,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) // We need to clean up the resources after our test await pool.destroy() @@ -1661,8 +1903,8 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() ).toStrictEqual({ runTime: { - aggregate: false, - average: false, + aggregate: true, + average: true, median: false }, waitTime: { @@ -1687,8 +1929,8 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() ).toStrictEqual({ runTime: { - aggregate: false, - average: false, + aggregate: true, + average: true, median: false }, waitTime: { @@ -1725,27 +1967,32 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.usage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: { + runTime: expect.objectContaining({ history: expect.any(CircularArray) - }, + }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1757,11 +2004,21 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategy ).roundId ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).workerNodeId + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1795,27 +2052,32 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.usage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: { + runTime: expect.objectContaining({ history: expect.any(CircularArray) - }, + }), waitTime: { - history: expect.any(CircularArray) + history: new CircularArray() }, elu: { idle: { - history: expect.any(CircularArray) + history: new CircularArray() }, active: { - history: expect.any(CircularArray) + history: new CircularArray() } } }) + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1827,11 +2089,21 @@ describe('Selection strategies test suite', () => { pool.workerChoiceStrategyContext.workerChoiceStrategy ).roundId ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).workerNodeId + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toEqual(expect.any(Number)) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1857,11 +2129,21 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).roundId ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).workerNodeId + ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ).nextWorkerNodeKey ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -1875,14 +2157,24 @@ describe('Selection strategies test suite', () => { pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).roundId ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).workerNodeId + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1890,7 +2182,7 @@ describe('Selection strategies test suite', () => { ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).roundWeights ).toStrictEqual([ pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1908,11 +2200,21 @@ describe('Selection strategies test suite', () => { workerChoiceStrategy ).roundId ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).workerNodeId + ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ).nextWorkerNodeKey ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -1924,11 +2226,26 @@ describe('Selection strategies test suite', () => { ).roundWeights ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).roundId + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).workerNodeId + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy ).nextWorkerNodeKey ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy @@ -1936,7 +2253,7 @@ describe('Selection strategies test suite', () => { ).toBeGreaterThan(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy + pool.workerChoiceStrategyContext.workerChoiceStrategy ).roundWeights ).toStrictEqual([ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(