* A ready worker whose execution is held open until ControllableReadyProc.release * is called. ControllableReadyProc.dispatched resolves the moment the worker * receives its `execute` message — i.e. once the scheduler has counted the execution as * active — giving tests a determin
()
| 97 | * its `ready` event is emitted only after the module attaches its listeners. |
| 98 | */ |
| 99 | function createControllableReadyProc(): ControllableReadyProc { |
| 100 | let markDispatched: () => void = () => {} |
| 101 | const dispatched = new Promise<void>((resolve) => { |
| 102 | markDispatched = resolve |
| 103 | }) |
| 104 | let proc: MockProc | undefined |
| 105 | let lastExecutionId = 0 |
| 106 | |
| 107 | const spawn: SpawnFactory = () => { |
| 108 | const current = createBaseProc() |
| 109 | current.send = (message: unknown) => { |
| 110 | const msg = message as { type?: string; executionId?: number } |
| 111 | if (msg.type === 'execute') { |
| 112 | lastExecutionId = msg.executionId ?? 0 |
| 113 | markDispatched() |
| 114 | } |
| 115 | return true |
| 116 | } |
| 117 | setImmediate(() => current.emit('message', { type: 'ready' })) |
| 118 | proc = current |
| 119 | return current |
| 120 | } |
| 121 | |
| 122 | const release = (result: unknown = 'released') => { |
| 123 | proc?.emit('message', { |
| 124 | type: 'result', |
| 125 | executionId: lastExecutionId, |
| 126 | result: { result, stdout: '' }, |
| 127 | }) |
| 128 | } |
| 129 | |
| 130 | return { spawn, dispatched, release } |
| 131 | } |
| 132 | |
| 133 | function createReadyFetchProxyProc(fetchMessage: { url: string; optionsJson?: string }): MockProc { |
| 134 | const proc = createBaseProc() |