X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fselection-strategies.test.js;h=77713b6f03f20f8dc883cad07820b292a16d47de;hb=60bde24c50f1c5b52cf988af05332fe2c8ee25e9;hp=167736edb9f11c24da068a0b43da56c48db14344;hpb=715143510b6627ffeb2735f42bb682935f16b9e9;p=poolifier.git diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 167736ed..77713b6f 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -1,9 +1,9 @@ const { expect } = require('expect') const { - WorkerChoiceStrategies, DynamicThreadPool, + FixedClusterPool, FixedThreadPool, - FixedClusterPool + WorkerChoiceStrategies } = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array') @@ -79,7 +79,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) } else if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { expect( @@ -98,7 +98,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -123,7 +123,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 +134,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() @@ -215,6 +217,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { @@ -236,7 +239,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( WorkerChoiceStrategies.ROUND_ROBIN - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -259,10 +262,11 @@ 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: { @@ -280,11 +284,15 @@ describe('Selection strategies test suite', () => { } } }) + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( WorkerChoiceStrategies.ROUND_ROBIN - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -326,13 +334,13 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) await pool.destroy() pool = new DynamicThreadPool( @@ -344,13 +352,13 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -364,7 +372,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 +383,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,6 +466,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { @@ -503,6 +514,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { @@ -537,7 +549,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 +560,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,24 +637,19 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toStrictEqual({ + expect(workerNode.usage).toMatchObject({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - aggregate: expect.any(Number), - maximum: expect.any(Number), - minimum: expect.any(Number), history: expect.any(CircularArray) }, waitTime: { - aggregate: expect.any(Number), - maximum: expect.any(Number), - minimum: expect.any(Number), history: expect.any(CircularArray) }, elu: { @@ -656,8 +665,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) - expect(workerNode.usage.waitTime.aggregate).toBeGreaterThanOrEqual(0) + if (workerNode.usage.runTime.aggregate == null) { + expect(workerNode.usage.runTime.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.waitTime.aggregate == null) { + expect(workerNode.usage.waitTime.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0) + } } // We need to clean up the resources after our test await pool.destroy() @@ -678,24 +695,19 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.usage).toStrictEqual({ + expect(workerNode.usage).toMatchObject({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { - aggregate: expect.any(Number), - maximum: expect.any(Number), - minimum: expect.any(Number), history: expect.any(CircularArray) }, waitTime: { - aggregate: expect.any(Number), - maximum: expect.any(Number), - minimum: expect.any(Number), history: expect.any(CircularArray) }, elu: { @@ -711,8 +723,16 @@ describe('Selection strategies test suite', () => { expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) - expect(workerNode.usage.waitTime.aggregate).toBeGreaterThanOrEqual(0) + if (workerNode.usage.runTime.aggregate == null) { + expect(workerNode.usage.runTime.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) + } + if (workerNode.usage.waitTime.aggregate == null) { + expect(workerNode.usage.waitTime.aggregate).toBeUndefined() + } else { + expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0) + } } // We need to clean up the resources after our test await pool.destroy() @@ -726,7 +746,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -736,7 +757,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() @@ -818,6 +840,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { @@ -827,12 +850,12 @@ describe('Selection strategies test suite', () => { history: expect.any(CircularArray) }, elu: { - idle: expect.objectContaining({ + idle: { history: expect.any(CircularArray) - }), - active: expect.objectContaining({ + }, + active: { history: expect.any(CircularArray) - }) + } } }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) @@ -871,6 +894,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { @@ -880,12 +904,12 @@ describe('Selection strategies test suite', () => { history: expect.any(CircularArray) }, elu: { - idle: expect.objectContaining({ + idle: { history: expect.any(CircularArray) - }), - active: expect.objectContaining({ + }, + active: { history: expect.any(CircularArray) - }) + } } }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) @@ -911,7 +935,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: false + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -921,7 +946,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() @@ -1003,21 +1029,22 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: expect.objectContaining({ + runTime: { history: expect.any(CircularArray) - }), + }, waitTime: { history: expect.any(CircularArray) }, elu: { - idle: expect.objectContaining({ + idle: { history: expect.any(CircularArray) - }), - active: expect.objectContaining({ + }, + active: { history: expect.any(CircularArray) - }) + } } }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) @@ -1071,21 +1098,22 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: expect.objectContaining({ + runTime: { history: expect.any(CircularArray) - }), + }, waitTime: { history: expect.any(CircularArray) }, elu: { - idle: expect.objectContaining({ + idle: { history: expect.any(CircularArray) - }), - active: expect.objectContaining({ + }, + active: { history: expect.any(CircularArray) - }) + } } }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) @@ -1144,21 +1172,22 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, - runTime: expect.objectContaining({ + runTime: { history: expect.any(CircularArray) - }), + }, waitTime: { history: expect.any(CircularArray) }, elu: { - idle: expect.objectContaining({ + idle: { history: expect.any(CircularArray) - }), - active: expect.objectContaining({ + }, + active: { history: expect.any(CircularArray) - }) + } } }) expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) @@ -1273,7 +1302,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -1283,7 +1313,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() @@ -1365,6 +1396,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: expect.objectContaining({ @@ -1432,15 +1464,12 @@ 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) }, @@ -1457,8 +1486,16 @@ 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( @@ -1500,15 +1537,12 @@ 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) }, @@ -1525,8 +1559,16 @@ 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( @@ -1551,7 +1593,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1567,7 +1609,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1588,7 +1630,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1604,7 +1646,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1629,7 +1671,8 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy } ) expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({ - useDynamicWorker: true + dynamicWorkerUsage: false, + dynamicWorkerReady: true }) await pool.destroy() pool = new DynamicThreadPool( @@ -1639,7 +1682,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() @@ -1725,6 +1769,7 @@ describe('Selection strategies test suite', () => { executing: 0, queued: 0, maxQueued: 0, + stolen: 0, failed: 0 }, runTime: { @@ -1756,7 +1801,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1791,10 +1836,11 @@ 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: { @@ -1812,6 +1858,10 @@ describe('Selection strategies test suite', () => { } } }) + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1826,7 +1876,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1856,7 +1906,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1877,7 +1927,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1907,7 +1957,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1923,7 +1973,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get(