Build a pool with a counting fake-worker factory.
(
size: number,
behavior: (m: ParseMsg) => Action,
opts: Partial<{ recycleInterval: number; parseTimeoutMs: number }> = {}
)
| 65 | |
| 66 | /** Build a pool with a counting fake-worker factory. */ |
| 67 | function makePool( |
| 68 | size: number, |
| 69 | behavior: (m: ParseMsg) => Action, |
| 70 | opts: Partial<{ recycleInterval: number; parseTimeoutMs: number }> = {} |
| 71 | ) { |
| 72 | let spawned = 0, terminated = 0; |
| 73 | const pool = new ParseWorkerPool({ |
| 74 | languages: ['typescript'] as Language[], |
| 75 | size, |
| 76 | recycleInterval: opts.recycleInterval, |
| 77 | parseTimeoutMs: opts.parseTimeoutMs, |
| 78 | createWorker: () => { spawned++; return new FakeWorker(behavior, () => { terminated++; }); }, |
| 79 | }); |
| 80 | return { pool, counts: () => ({ spawned, terminated }) }; |
| 81 | } |
| 82 | |
| 83 | describe('resolveParsePoolSize', () => { |
| 84 | it('treats explicit 0 and 1 as a single worker (the rollback path)', () => { |