import { DynamicPoolWorkerChoiceStrategy } from './dynamic-pool-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
+ RequiredStatistics,
WorkerChoiceStrategy
} from './selection-strategies-types'
import { WorkerChoiceStrategies } from './selection-strategies-types'
* Gets the worker choice strategy used in the context.
*
* @returns The worker choice strategy.
+ * @deprecated Scheduled removal.
*/
public getWorkerChoiceStrategy (): IWorkerChoiceStrategy {
return this.workerChoiceStrategy
}
+ /**
+ * Gets the worker choice strategy required statistics.
+ *
+ * @returns The required statistics.
+ */
+ public getRequiredStatistics (): RequiredStatistics {
+ return this.workerChoiceStrategy.requiredStatistics
+ }
+
/**
* Sets the worker choice strategy to use in the context.
*
public execute (): number {
return this.workerChoiceStrategy.choose()
}
+
+ /**
+ * Removes a worker in the underlying selection strategy internals.
+ *
+ * @param workerKey - The key of the worker to remove.
+ * @returns `true` if the removal is successful, `false` otherwise.
+ */
+ public remove (workerKey: number): boolean {
+ return this.workerChoiceStrategy.remove(workerKey)
+ }
}
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(false)
// We need to clean up the resources after our test
await pool.destroy()
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(false)
// We need to clean up the resources after our test
await pool.destroy()
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
promises.push(pool.execute())
}
await Promise.all(promises)
+ expect(
+ pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ .workerLastVirtualTaskTimestamp.size
+ ).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
})
promises.push(pool.execute())
}
await Promise.all(promises)
+ // expect(
+ // pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ // .workerChoiceStrategy.workerLastVirtualTaskTimestamp.size
+ // ).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
})
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
promises.push(pool.execute())
}
await Promise.all(promises)
+ expect(
+ pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ .workersTaskRunTime.size
+ ).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
})
promises.push(pool.execute())
}
await Promise.all(promises)
+ // expect(
+ // pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ // .workerChoiceStrategy.workersTaskRunTime.size
+ // ).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
})