* A fake whose grammar load takes `loadMs` (or never finishes, with `null`), and * which records when it finished loading and when it was terminated.
| 318 | * which records when it finished loading and when it was terminated. |
| 319 | */ |
| 320 | class SlowLoadWorker implements ParsePoolWorker { |
| 321 | private msgCb?: (m: unknown) => void; |
| 322 | private exitCb?: (code: number) => void; |
| 323 | loadedAt: number | null = null; |
| 324 | terminatedAt: number | null = null; |
| 325 | constructor(private loadMs: number | null) {} |
| 326 | on(event: string, cb: (...args: any[]) => void): void { |
| 327 | if (event === 'message') this.msgCb = cb; |
| 328 | else if (event === 'exit') this.exitCb = cb; |
| 329 | } |
| 330 | postMessage(msg: unknown): void { |
| 331 | if ((msg as { type: string }).type !== 'load-grammars' || this.loadMs === null) return; |
| 332 | setTimeout(() => { |
| 333 | if (this.terminatedAt !== null) return; |
| 334 | this.loadedAt = performance.now(); |
| 335 | this.msgCb?.({ type: 'grammars-loaded' }); |
| 336 | }, this.loadMs); |
| 337 | } |
| 338 | exit(code: number): void { this.exitCb?.(code); } |
| 339 | terminate(): Promise<number> { this.terminatedAt = performance.now(); return Promise.resolve(0); } |
| 340 | } |
| 341 | |
| 342 | describe('teardown never terminates a worker mid-load', () => { |
| 343 | // Terminating a worker whose grammar WASM is still compiling can crash the |
nothing calls this directly
no outgoing calls
no test coverage detected