import { describe, it, expect } from 'vitest' import { createLimiter } from '../src/main/concurrency' describe('createLimiter', () => { it('동시 실행 수가 limit을 넘지 않는다', async () => { const limit = createLimiter(2) let active = 0 let maxActive = 0 const task = () => limit(async () => { active++ maxActive = Math.max(maxActive, active) await new Promise((r) => setTimeout(r, 10)) active-- }) await Promise.all(Array.from({ length: 10 }, task)) expect(maxActive).toBeLessThanOrEqual(2) }) it('모든 작업의 결과를 반환한다', async () => { const limit = createLimiter(3) const results = await Promise.all( Array.from({ length: 5 }, (_, i) => limit(async () => i * 2)) ) expect(results).toEqual([0, 2, 4, 6, 8]) }) })