+ })
+ pool.setWorkerChoiceStrategyOptions({
+ runTime: { median: true },
+ elu: { median: true }
+ })
+ expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
+ runTime: { median: true },
+ elu: { median: true }
+ })
+ for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
+ .workerChoiceStrategies) {
+ expect(workerChoiceStrategy.opts).toStrictEqual({
+ runTime: { median: true },
+ elu: { median: true }
+ })
+ }
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
+ runTime: {
+ aggregate: true,
+ average: false,
+ median: true
+ },
+ waitTime: {
+ aggregate: false,
+ average: false,
+ median: false
+ },
+ elu: {
+ aggregate: true,
+ average: false,
+ median: true
+ }
+ })
+ pool.setWorkerChoiceStrategyOptions({
+ runTime: { median: false },
+ elu: { median: false }
+ })
+ expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
+ runTime: { median: false },
+ elu: { median: false }
+ })
+ for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
+ .workerChoiceStrategies) {
+ expect(workerChoiceStrategy.opts).toStrictEqual({
+ runTime: { median: false },
+ elu: { median: false }
+ })
+ }
+ expect(
+ pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ ).toStrictEqual({
+ runTime: {
+ aggregate: true,
+ average: true,
+ median: false
+ },
+ waitTime: {
+ aggregate: false,
+ average: false,
+ median: false
+ },
+ elu: {
+ aggregate: true,
+ average: true,
+ median: false
+ }
+ })
+ expect(() =>
+ pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions')
+ ).toThrowError(
+ 'Invalid worker choice strategy options: must be a plain object'
+ )
+ expect(() =>
+ pool.setWorkerChoiceStrategyOptions({ weights: {} })
+ ).toThrowError(
+ 'Invalid worker choice strategy options: must have a weight for each worker node'
+ )
+ expect(() =>
+ pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' })
+ ).toThrowError(
+ "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
+ )
+ await pool.destroy()
+ })
+
+ it('Verify that pool tasks queue can be enabled/disabled', async () => {
+ const pool = new FixedThreadPool(
+ numberOfWorkers,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ expect(pool.opts.enableTasksQueue).toBe(false)
+ expect(pool.opts.tasksQueueOptions).toBeUndefined()
+ pool.enableTasksQueue(true)
+ expect(pool.opts.enableTasksQueue).toBe(true)
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
+ pool.enableTasksQueue(true, { concurrency: 2 })
+ expect(pool.opts.enableTasksQueue).toBe(true)
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
+ pool.enableTasksQueue(false)
+ expect(pool.opts.enableTasksQueue).toBe(false)
+ expect(pool.opts.tasksQueueOptions).toBeUndefined()
+ await pool.destroy()
+ })
+
+ it('Verify that pool tasks queue options can be set', async () => {
+ const pool = new FixedThreadPool(
+ numberOfWorkers,
+ './tests/worker-files/thread/testWorker.js',
+ { enableTasksQueue: true }
+ )
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
+ pool.setTasksQueueOptions({ concurrency: 2 })
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
+ expect(() =>
+ pool.setTasksQueueOptions('invalidTasksQueueOptions')
+ ).toThrowError('Invalid tasks queue options: must be a plain object')
+ expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError(
+ "Invalid worker tasks concurrency '0'"
+ )
+ expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrowError(
+ 'Invalid worker tasks concurrency: must be an integer'
+ )
+ await pool.destroy()
+ })
+
+ it('Verify that pool info is set', async () => {
+ let pool = new FixedThreadPool(
+ numberOfWorkers,
+ './tests/worker-files/thread/testWorker.js'