Skip to content

Commit f247110

Browse files
committed
test(apple-runner): hang up on every read attempt without counting the connect loop
The read-only lost-response driver scripted 20 hang-ups and a 400 ms timeout. That count depended on the connect loop's retry cadence (RUNNER_CONNECT_ATTEMPT_INTERVAL_MS): with a faster cadence the queue runs out, and the fake answers the next attempt with `ok`. The fake runner server now has a `hangUpAlways` reply that is never consumed, so the read is refused until the loop gives up, however often it retries. The timeout now only bounds how long the loop runs. Mutation: set RUNNER_CONNECT_ATTEMPT_INTERVAL_MS to 10 or 50 (with a 1 ms retry base delay) -> ios-runner.status.read-only-completed-without-retained-reply still passes.
1 parent 50fc6fc commit f247110

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎packages/platform-apple/src/runner/__tests__/fake-runner-server.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export type FakeRunnerResponse =
1414
| { kind: 'ok'; data: Record<string, unknown> }
1515
| { kind: 'runnerError'; code: string; message: string }
1616
| { kind: 'hangUp' }
17+
/** Hangs up on this request and every later one for the command: the entry is never consumed. */
18+
| { kind: 'hangUpAlways' }
1719
/** Hangs up and stops listening, as a runner process that died mid-command. */
1820
| { kind: 'exit' };
1921

@@ -55,9 +57,11 @@ export async function startFakeRunnerServer(
5557
req.on('end', () => {
5658
const body = parseBody(raw);
5759
requests.push({ command: String(body.command ?? ''), body });
58-
const next = byCommand
59-
? (byCommand[String(body.command ?? '')]?.shift() ?? { kind: 'ok' as const, data: {} })
60-
: remaining.shift();
60+
const queue = byCommand ? byCommand[String(body.command ?? '')] : remaining;
61+
const next =
62+
queue?.[0]?.kind === 'hangUpAlways'
63+
? queue[0]
64+
: (queue?.shift() ?? (byCommand ? { kind: 'ok' as const, data: {} } : undefined));
6165
if (next?.kind === 'exit') {
6266
res.destroy();
6367
stopped ??= new Promise<void>((resolve) => server.close(() => resolve()));
@@ -89,7 +93,7 @@ function writeFakeRunnerResponse(
8993
res.end(JSON.stringify({ ok: false, error: { message: 'fake runner script exhausted' } }));
9094
return;
9195
}
92-
if (next.kind === 'hangUp') {
96+
if (next.kind === 'hangUp' || next.kind === 'hangUpAlways') {
9397
res.destroy();
9498
return;
9599
}

‎packages/platform-apple/src/runner/__tests__/runner-dispatch-disclosure.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,18 @@ async function replyFailure(code: string): Promise<unknown> {
7171
/**
7272
* The runner hangs up on the command, then answers the status probe with `status`. A read goes
7373
* through the connect loop, which posts again on each attempt, so the runner hangs up on every
74-
* attempt and the loop's simctl curl fallback times out after its POST.
74+
* attempt until the loop gives up, and the loop's simctl curl fallback times out after its POST.
75+
* The read's short timeout only bounds how long the loop runs.
7576
*/
7677
async function lostResponse(
7778
status: FakeRunnerResponse[],
7879
command: RunnerCommand = TAP,
7980
): Promise<unknown> {
8081
const readOnly = isReadOnlyRunnerCommand(command);
81-
const hangUps: FakeRunnerResponse[] = Array.from({ length: readOnly ? 20 : 1 }, () => ({
82-
kind: 'hangUp',
83-
}));
84-
server = await startFakeRunnerServer({ [command.command]: hangUps, status });
82+
server = await startFakeRunnerServer({
83+
[command.command]: [{ kind: readOnly ? 'hangUpAlways' : 'hangUp' }],
84+
status,
85+
});
8586
if (readOnly) {
8687
appleRunnerTestHost.update({
8788
runXcrun: vi.fn(async () => ({ exitCode: 28, stdout: '', stderr: 'curl exited 28' })),

0 commit comments

Comments
 (0)