import { runTasksWithBoundedConcurrency } from './attachment-autodownload-concurrency.rules'; describe('attachment-autodownload-concurrency.rules', () => { it('runs tasks with bounded concurrency', async () => { let active = 0; let maxActive = 0; const tasks = Array.from({ length: 6 }, (_, index) => async () => { active += 1; maxActive = Math.max(maxActive, active); await new Promise((resolve) => setTimeout(resolve, 5)); active -= 1; return index; }); const results = await runTasksWithBoundedConcurrency(tasks, 2); expect(results).toEqual([ 0, 1, 2, 3, 4, 5 ]); expect(maxActive).toBeLessThanOrEqual(2); }); });