- expect(longRunningPool.workers.length).toBe(max)
- await new Promise(resolve => setTimeout(resolve, 1000))
- // Here we expect the workers to be at the max size since that the task is still running
- expect(longRunningPool.workers.length).toBe(max)
+ expect(longRunningPool.workerNodes.length).toBe(max)
+ await waitWorkerEvents(longRunningPool, 'exit', max - min)
+ expect(longRunningPool.workerNodes.length).toBe(min)
+ expect(
+ longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ longRunningPool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).nextWorkerNodeKey
+ ).toBeLessThan(longRunningPool.workerNodes.length)
+ // We need to clean up the resources after our test
+ await longRunningPool.destroy()
+ })
+
+ it('Verify scale thread up and down is working when long executing task is used:soft', async () => {
+ const longRunningPool = new DynamicThreadPool(
+ min,
+ max,
+ './tests/worker-files/thread/longRunningWorkerSoftBehavior.js',
+ {
+ errorHandler: (e) => console.error(e),
+ onlineHandler: () => console.info('long executing worker is online'),
+ exitHandler: () => console.info('long executing worker exited')
+ }
+ )
+ expect(longRunningPool.workerNodes.length).toBe(min)
+ for (let i = 0; i < max * 2; i++) {
+ longRunningPool.execute()
+ }
+ expect(longRunningPool.workerNodes.length).toBe(max)
+ await sleep(1000)
+ // Here we expect the workerNodes to be at the max size since the task is still executing
+ expect(longRunningPool.workerNodes.length).toBe(max)
+ // We need to clean up the resources after our test
+ await longRunningPool.destroy()
+ })
+
+ it('Verify that a pool with zero worker can be instantiated', async () => {
+ const pool = new DynamicThreadPool(
+ 0,
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ expect(pool).toBeInstanceOf(DynamicThreadPool)
+ // We need to clean up the resources after our test
+ await pool.destroy()