X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract-pool.test.mjs;h=0c91349765f65c80884d4c50d8b45d93424e37fd;hb=f12182ad6dc553c7a5dfeee01bcde65c0177f671;hp=8cae47d6bdca9f2289a9844c655d602a670e4dd6;hpb=38e6b85b3247f847b61f30efc37851489f106e8a;p=poolifier.git diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 8cae47d6..0c913497 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url' import { expect } from 'expect' import { restore, stub } from 'sinon' -import { CircularArray } from '../../lib/circular-array.cjs' +import { CircularBuffer } from '../../lib/circular-buffer.cjs' import { DynamicClusterPool, DynamicThreadPool, @@ -761,17 +761,17 @@ describe('Abstract pool test suite', () => { failed: 0 }, runTime: { - history: new CircularArray() + history: expect.any(CircularBuffer) }, waitTime: { - history: new CircularArray() + history: expect.any(CircularBuffer) }, elu: { idle: { - history: new CircularArray() + history: expect.any(CircularBuffer) }, active: { - history: new CircularArray() + history: expect.any(CircularBuffer) } } }) @@ -789,7 +789,7 @@ describe('Abstract pool test suite', () => { expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue) expect(workerNode.tasksQueue.size).toBe(0) expect(workerNode.tasksQueue.maxSize).toBe(0) - expect(workerNode.tasksQueue.k).toBe(numberOfWorkers * 2) + expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2) } await pool.destroy() pool = new DynamicThreadPool( @@ -802,7 +802,7 @@ describe('Abstract pool test suite', () => { expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue) expect(workerNode.tasksQueue.size).toBe(0) expect(workerNode.tasksQueue.maxSize).toBe(0) - expect(workerNode.tasksQueue.k).toBe(numberOfWorkers * 2) + expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2) } await pool.destroy() }) @@ -933,17 +933,17 @@ describe('Abstract pool test suite', () => { failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, waitTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, elu: { idle: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, active: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) } } }) @@ -961,17 +961,17 @@ describe('Abstract pool test suite', () => { failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, waitTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, elu: { idle: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, active: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) } } }) @@ -1003,17 +1003,17 @@ describe('Abstract pool test suite', () => { failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, waitTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, elu: { idle: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, active: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) } } }) @@ -1021,10 +1021,6 @@ describe('Abstract pool test suite', () => { expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( numberOfWorkers * maxMultiplier ) - expect(workerNode.usage.runTime.history.length).toBe(0) - expect(workerNode.usage.waitTime.history.length).toBe(0) - expect(workerNode.usage.elu.idle.history.length).toBe(0) - expect(workerNode.usage.elu.active.history.length).toBe(0) } pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) for (const workerNode of pool.workerNodes) { @@ -1039,17 +1035,17 @@ describe('Abstract pool test suite', () => { failed: 0 }, runTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, waitTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, elu: { idle: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, active: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) } } }) @@ -1057,10 +1053,6 @@ describe('Abstract pool test suite', () => { expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( numberOfWorkers * maxMultiplier ) - expect(workerNode.usage.runTime.history.length).toBe(0) - expect(workerNode.usage.waitTime.history.length).toBe(0) - expect(workerNode.usage.elu.idle.history.length).toBe(0) - expect(workerNode.usage.elu.active.history.length).toBe(0) } await pool.destroy() }) @@ -1452,17 +1444,17 @@ describe('Abstract pool test suite', () => { failed: 0 }, runTime: { - history: new CircularArray() + history: expect.any(CircularBuffer) }, waitTime: { - history: new CircularArray() + history: expect.any(CircularBuffer) }, elu: expect.objectContaining({ idle: expect.objectContaining({ - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }), active: expect.objectContaining({ - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }) }) }) @@ -1669,6 +1661,76 @@ describe('Abstract pool test suite', () => { { name: 'fibonacci' } ]) expect(workerNode.taskFunctionsUsage.size).toBe(3) + expect(workerNode.usage.tasks.executed).toBeGreaterThan(0) + for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) { + expect( + workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name) + ).toStrictEqual({ + tasks: { + executed: expect.any(Number), + executing: 0, + failed: 0, + queued: 0, + sequentiallyStolen: 0, + stolen: 0 + }, + runTime: { + history: expect.any(CircularBuffer) + }, + waitTime: { + history: expect.any(CircularBuffer) + }, + elu: { + idle: { + history: expect.any(CircularBuffer) + }, + active: { + history: expect.any(CircularBuffer) + } + } + }) + expect( + workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name) + .tasks.executed + ).toBeGreaterThan(0) + } + expect( + workerNode.getTaskFunctionWorkerUsage(DEFAULT_TASK_NAME) + ).toStrictEqual( + workerNode.getTaskFunctionWorkerUsage( + workerNode.info.taskFunctionsProperties[1].name + ) + ) + } + await pool.destroy() + }) + + it('Verify that task function objects worker is working', async () => { + const pool = new DynamicThreadPool( + Math.floor(numberOfWorkers / 2), + numberOfWorkers, + './tests/worker-files/thread/testTaskFunctionObjectsWorker.mjs' + ) + const data = { n: 10 } + const result0 = await pool.execute(data) + expect(result0).toStrictEqual({ ok: 1 }) + const result1 = await pool.execute(data, 'jsonIntegerSerialization') + expect(result1).toStrictEqual({ ok: 1 }) + const result2 = await pool.execute(data, 'factorial') + expect(result2).toBe(3628800) + const result3 = await pool.execute(data, 'fibonacci') + expect(result3).toBe(55) + expect(pool.info.executingTasks).toBe(0) + expect(pool.info.executedTasks).toBe(4) + for (const workerNode of pool.workerNodes) { + expect(workerNode.info.taskFunctionsProperties).toStrictEqual([ + { name: DEFAULT_TASK_NAME }, + { name: 'jsonIntegerSerialization' }, + { name: 'factorial' }, + { name: 'fibonacci' } + ]) + expect(workerNode.taskFunctionsUsage.size).toBe(3) + expect(workerNode.usage.tasks.executed).toBeGreaterThan(0) for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) { expect( workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name) @@ -1682,17 +1744,17 @@ describe('Abstract pool test suite', () => { stolen: 0 }, runTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, waitTime: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, elu: { idle: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) }, active: { - history: expect.any(CircularArray) + history: expect.any(CircularBuffer) } } })