test(http): deadline 분류 시험이 대기 지점에서 가짜 시계로 deadline을 낸다
문제: 「times out at the <phase> wait when the deadline fires」가 실제 시계로 30ms deadline을 잡는다. 전송 실패(transport backoff)나 503 (retry backoff)을 처리하는 시점에 이미 30ms가 지났으면 실행기는 backoff할 시간이 없다고 보고 그 실패로 끝낸다(`remaining() > 0`이 거짓). 그래서 기대한 TIMEOUT 대신 NETWORK_FAILURE·503 결과가 나온다. desktop 부하 31에서 한 번 떨어졌다(PR #19 W2-FE 기록 F). 고른 방법: deadline 경우만 가짜 시계(`vi.useFakeTimers`)로 돌고, 그 대기에 닿은 것을 확인한 뒤 30ms를 진행한다. 시험이 보려는 것(대기 중에 deadline이 나면 DEADLINE·TIMEOUT)을 그대로 보고 기계 속도에는 기대지 않는다. 두 backoff 단계는 답하기 전에 실제 시간 40ms를 멈춘다 (`Atomics.wait`). 실제 시계로 되돌리면 이 시험이 매번 실패한다. - 버린 대안: deadline을 늘리기. 경쟁이 남고 규칙 밖이다. - 버린 대안: `vi.waitFor`로 기다리기. 가짜 시계에서는 확인할 때마다 시계를 진행해 대기에 닿기 전에 deadline이 날 수 있다. 위험·한계: 실행기 동작은 바꾸지 않았다. deadline이 이미 지난 뒤 도착한 전송 실패를 NETWORK_FAILURE로 보고하는 것이 맞는지는 이 커밋이 정하지 않는다. 검증(desktop): 시험 파일 72개 3회 연속 통과. 변이: 가짜 시계를 빼고 실제 30ms deadline에 같은 40ms 멈춤을 두면 transport backoff·retry backoff 둘이 매번 실패(나머지 넷 통과). eslint·check:types rc=0. 로그 /tmp/claude-gates/w2fe2-http1·2/.
This commit is contained in:
@@ -972,8 +972,29 @@ describe("terminal owner classification at every wait", () => {
|
||||
type Owner = "CALLER" | "SCOPE_FENCE" | "DEADLINE";
|
||||
|
||||
const hang = () => new Promise<never>(() => {});
|
||||
/**
|
||||
* Blocks this thread for `ms` of real time, as a loaded machine does
|
||||
* between two steps. A fake clock does not move meanwhile.
|
||||
*/
|
||||
const stallRealTime = (ms: number) =>
|
||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
||||
|
||||
async function endWaitAt(phase: Phase, owner: Owner) {
|
||||
// The deadline fires on a fake clock once the wait under test is reached.
|
||||
// On the real clock a 30ms deadline raced the machine: a transport failure
|
||||
// or a 503 handled after 30ms found no time left to back off, and the
|
||||
// request ended as that failure instead of TIMEOUT (seen at load 31).
|
||||
// The backoff phases stall 40ms of real time before answering, so a real
|
||||
// deadline here fails every time.
|
||||
if (owner === "DEADLINE") vi.useFakeTimers();
|
||||
try {
|
||||
return await endWaitAtOnClock(phase, owner);
|
||||
} finally {
|
||||
if (owner === "DEADLINE") vi.useRealTimers();
|
||||
}
|
||||
}
|
||||
|
||||
async function endWaitAtOnClock(phase: Phase, owner: Owner) {
|
||||
const caller = new AbortController();
|
||||
const fence = new AbortController();
|
||||
const fencedScope = Object.freeze({
|
||||
@@ -1008,6 +1029,7 @@ describe("terminal owner classification at every wait", () => {
|
||||
? (reach(), hang())
|
||||
: { kind: "READY", headers: {} },
|
||||
fetcher: vi.fn(async () => {
|
||||
if (owner === "DEADLINE" && phase.endsWith("backoff")) stallRealTime(40);
|
||||
switch (phase) {
|
||||
case "transport backoff":
|
||||
throw new TypeError("network down");
|
||||
@@ -1043,12 +1065,17 @@ describe("terminal owner classification at every wait", () => {
|
||||
...(execution === undefined ? {} : { execution }),
|
||||
},
|
||||
);
|
||||
if (owner !== "DEADLINE") {
|
||||
await vi.waitFor(() =>
|
||||
expect(reached || execution?.traffic.concurrency.queued === 1).toBe(
|
||||
true,
|
||||
),
|
||||
);
|
||||
const waiting = () =>
|
||||
reached || execution?.traffic.concurrency.queued === 1;
|
||||
if (owner === "DEADLINE") {
|
||||
// vi.waitFor would advance the fake clock on every check.
|
||||
for (let turn = 0; turn < 100 && !waiting(); turn += 1) {
|
||||
await flushMicrotasks();
|
||||
}
|
||||
expect(waiting()).toBe(true);
|
||||
await vi.advanceTimersByTimeAsync(30);
|
||||
} else {
|
||||
await vi.waitFor(() => expect(waiting()).toBe(true));
|
||||
(owner === "CALLER" ? caller : fence).abort();
|
||||
}
|
||||
const outcome = await pending;
|
||||
|
||||
Reference in New Issue
Block a user