Skip to content

Commit 7093459

Browse files
committed
test(claude): give the idle-ping test headroom against timer scheduling
Failed on macos-latest while passing everywhere else. The upstream went silent for 90ms with a 25ms ping interval and the test asserted >=3 pings — a margin of 3.6 intervals. One coalesced timer on a loaded runner is enough to miss it, and timer scheduling is best-effort by definition. Silence goes to 300ms, twelve intervals against the same >=3. The assertion is untouched: it still proves idle pings flow during upstream silence, it just no longer depends on the runner delivering timers on schedule. Ablated by disabling the ping branch in src/claude/outbound.ts — the test fails, so the headroom did not hollow it out.
1 parent 81f3f68 commit 7093459

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

tests/claude-outbound.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,28 @@ describe("claude outbound SSE", () => {
341341
});
342342

343343
test("idle keepalive pings flow during upstream silence", async () => {
344-
// Upstream: created frame, 90ms of silence, then a clean completion.
344+
// Upstream: created frame, a stretch of silence, then a clean completion.
345+
//
346+
// The silence is deliberately many intervals long. At 90ms with a 25ms ping the
347+
// margin was 3.6 intervals against a >=3 assertion, so a single coalesced timer on
348+
// a loaded runner failed it — which is how this went red on macos-latest while
349+
// passing everywhere else. Timer scheduling is best-effort, not exact.
350+
//
351+
// The assertion below is unchanged. What changed is the headroom: the test still
352+
// proves idle pings flow during silence, it just no longer depends on the runner
353+
// delivering timers on schedule.
354+
const PING_INTERVAL_MS = 25;
355+
const SILENCE_MS = 300;
345356
const encoder = new TextEncoder();
346357
const upstream = new ReadableStream<Uint8Array>({
347358
async start(controller) {
348359
controller.enqueue(encoder.encode(sse("response.created", { response: {} })));
349-
await new Promise(r => setTimeout(r, 90));
360+
await new Promise(r => setTimeout(r, SILENCE_MS));
350361
controller.enqueue(encoder.encode(sse("response.completed", { response: { status: "completed", usage: { input_tokens: 1, output_tokens: 1 } } })));
351362
controller.close();
352363
},
353364
});
354-
const events = await collectEvents(responsesSseToAnthropicSse(upstream, "m", { pingIntervalMs: 25 }));
365+
const events = await collectEvents(responsesSseToAnthropicSse(upstream, "m", { pingIntervalMs: PING_INTERVAL_MS }));
355366
const pings = events.filter(e => e.name === "ping").length;
356367
expect(pings).toBeGreaterThanOrEqual(3); // startup ping + >=2 idle pings
357368
expect(events.at(-1)!.name).toBe("message_stop");

0 commit comments

Comments
 (0)