+ expect(result).toBe(false)
+ })
+
+ it("Verify that 'busy' event is emitted", async () => {
+ let poolBusy = 0
+ pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
+ for (let i = 0; i < numberOfThreads * 2; i++) {
+ pool.execute()
+ }
+ // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
+ // So in total numberOfThreads + 1 times for a loop submitting up to numberOfThreads * 2 tasks to the fixed pool.
+ expect(poolBusy).toBe(numberOfThreads + 1)
+ })
+
+ it('Verify that tasks queuing is working', async () => {
+ const maxMultiplier = 10
+ const promises = new Set()
+ for (let i = 0; i < numberOfThreads * maxMultiplier; i++) {
+ promises.add(queuePool.execute())
+ }
+ expect(promises.size).toBe(numberOfThreads * maxMultiplier)
+ for (const workerNode of queuePool.workerNodes) {
+ expect(workerNode.tasksUsage.running).toBeLessThanOrEqual(
+ queuePool.opts.tasksQueueOptions.concurrency
+ )
+ expect(workerNode.tasksUsage.run).toBe(0)
+ expect(workerNode.tasksQueue.length).toBeGreaterThan(0)
+ }
+ expect(queuePool.numberOfRunningTasks).toBe(numberOfThreads)
+ expect(queuePool.numberOfQueuedTasks).toBe(
+ numberOfThreads * maxMultiplier - numberOfThreads
+ )
+ await Promise.all(promises)
+ for (const workerNode of queuePool.workerNodes) {
+ expect(workerNode.tasksUsage.running).toBe(0)
+ expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.length).toBe(0)
+ }
+ promises.clear()