From: Jérôme Benoit Date: Thu, 8 Jun 2023 23:31:42 +0000 (+0200) Subject: test: add least ELU execution test X-Git-Tag: v2.6.0~7^2~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c5ad42cdf9da4841898649f28bd001f8c227b74b;p=poolifier.git test: add least ELU execution test Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 08682d92..20490d03 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -611,6 +611,64 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it.only('Verify LEAST_ELU strategy can be run in a fixed pool', async () => { + const pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU } + ) + // TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose` + const promises = new Set() + const maxMultiplier = 2 + for (let i = 0; i < max * maxMultiplier; i++) { + promises.add(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + const expectedWorkerUsage = { + tasks: { + executed: expect.any(Number), + executing: 0, + queued: 0, + failed: 0 + }, + runTime: { + aggregation: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + }, + waitTime: { + aggregation: 0, + average: 0, + median: 0, + history: expect.any(CircularArray) + } + } + if (workerNode.workerUsage.elu === undefined) { + expect(workerNode.workerUsage).toStrictEqual({ + ...expectedWorkerUsage, + elu: undefined + }) + } else { + expect(workerNode.workerUsage).toStrictEqual({ + ...expectedWorkerUsage, + elu: { + active: expect.any(Number), + idle: 0, + utilization: 1 + } + }) + } + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) + } + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE let pool = new FixedThreadPool(