From ce191bef4be65d6eaf4067017ec8a9dce4c0094d Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:29:33 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=9A=B4=EC=98=81=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=20=EC=83=81=EC=88=98=EB=A5=BC=20=EC=8B=A4=EC=A0=9C=20=EC=8B=9C?= =?UTF-8?q?=EA=B3=84=EB=A1=9C=20=EA=B8=B0=EB=8B=A4=EB=A6=AC=EB=8A=94=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=205=EA=B0=9C=EB=A5=BC=20=EB=B9=A0?= =?UTF-8?q?=EB=A5=B4=EA=B2=8C=20=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 테스트 5개가 운영 코드의 시간 상수를 실제 시계로 기다린다. - tests/unit/service-worker-runtime.test.ts "bounds a stream that never produces a chunk": ACTIVATION_MARKER_READ_DEADLINE_MS(5초)를 그대로 기다린다. 10초 제한 중 5초를 쓴다. - tests/unit/browser-rpc/browser-rpc-remediation.test.ts "keeps the operation DRAINING when waitClosed …" 4개: 닫힘 확인이 없으면 stream 정리가 STREAM_CLEANUP_BOUND_MS(1초)를 기다린다. 각 1초. 고른 방법과 버린 대안 - SW 테스트: 이 테스트만 vi.useFakeTimers()로 돌리고 deadline을 advanceTimersByTimeAsync로 넘긴다. 마커를 여러 번 읽을 수 있어 끝날 때까지 5초씩 최대 4번 넘긴다. deadline이 없으면 활성화가 끝나지 않아 "settled" 단언에서 실패한다. - RPC 테스트: 런타임은 이미 ClockPort를 주입받는다. 모든 대기를 30ms로 자르는 시스템 시계를 넘긴다. 작업 자체의 25ms deadline은 그 아래라 그대로다. - SW lifecycle이 deadline을 의존성으로 받게 하는 안은 버렸다. 운영 코드에 테스트용 손잡이를 하나 더 열어야 한다. - 상수 값(5,000·1,000)은 운영 코드 한 곳에 그대로 있다. 위험·한계 - 가짜 시계가 stream·마이크로태스크 순서와 얽히면 SW 테스트가 불안정해질 수 있다. 그때는 실제 시계로 되돌린다(1101/10-07 재검토 조건). - 완료 기준(각 100ms 아래)은 junit 시간으로 desktop에서 본다. 검증 - desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/service-worker-runtime.test.ts tests/unit/browser-rpc/browser-rpc-remediation.test.ts --reporter=junit --outputFile.junit=artifacts/tests/r1105-10-07.xml - 실행 시간만 바꾼 커밋이라 RED는 없다. 두 파일이 통과하고 다섯 테스트가 각각 100ms 아래여야 한다. Refs: 1101/10-07 --- .../browser-rpc-remediation.test.ts | 15 ++++++ tests/unit/service-worker-runtime.test.ts | 48 +++++++++++++------ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/tests/unit/browser-rpc/browser-rpc-remediation.test.ts b/tests/unit/browser-rpc/browser-rpc-remediation.test.ts index fa71da42..7167788f 100644 --- a/tests/unit/browser-rpc/browser-rpc-remediation.test.ts +++ b/tests/unit/browser-rpc/browser-rpc-remediation.test.ts @@ -8,6 +8,8 @@ import { type BrowserRpcTransport, } from "../../../src/adapters/browser-rpc/index.ts"; import { decodeServerStreamLease } from "../../../src/adapters/browser-rpc/transport.ts"; +import { systemClock } from "../../../src/adapters/platform/system-clock.ts"; +import type { ClockPort } from "../../../src/application/ports/clock-port.ts"; import { installBrowserRpcContractBindings } from "../../../src/contracts/browser-rpc.ts"; import { MAPPERS, @@ -539,6 +541,18 @@ describe("RPC-01 only a positive receipt confirms physical closure", () => { { label: "never settles", waitClosed: () => new Promise(() => {}) }, ]; + /** + * 1101/10-07. The system clock with every wait capped at 30 ms. Without a + * positive receipt the stream cleanup waits out its 1 s bound; capped, the + * test passes that bound instead of sleeping through it. The operation's own + * 25 ms deadlines are below the cap and unchanged. + */ + const cappedClock: ClockPort = Object.freeze({ + now: () => systemClock.now(), + sleep: (milliseconds: number, signal?: AbortSignal) => + systemClock.sleep(Math.min(milliseconds, 30), signal), + }); + for (const { label, waitClosed } of negativeReceipts) { it(`keeps the operation DRAINING when waitClosed ${label}`, async () => { const probe = leaseProbeWith(waitClosed); @@ -549,6 +563,7 @@ describe("RPC-01 only a positive receipt confirms physical closure", () => { mappers: MAPPERS, requestEncoders: { RpcResourceStreamRequestEncoder: STREAM_ENCODER }, transports: { CONNECT_REFERENCE_STREAM: probe.transport }, + clock: cappedClock, }); const stream = runtime.bindServerStream( "WATCH_RPC_RESOURCES", diff --git a/tests/unit/service-worker-runtime.test.ts b/tests/unit/service-worker-runtime.test.ts index bd57ca01..930496cc 100644 --- a/tests/unit/service-worker-runtime.test.ts +++ b/tests/unit/service-worker-runtime.test.ts @@ -2004,22 +2004,40 @@ describe("SW-01 the activation marker read is bounded in bytes", () => { }); it("bounds a stream that never produces a chunk", async () => { - let cancels = 0; - const stalled = new ReadableStream({ - pull() { - return new Promise(() => {}); - }, - cancel() { - cancels += 1; - }, - }); - const fixture = scopeWithMarkerBody(stalled); + // 1101/10-07. The read deadline is the runtime's own 5 s constant. The + // clock is faked, so the test passes the deadline instead of waiting it + // out; without a deadline the activation never settles and this fails. + vi.useFakeTimers(); + try { + let cancels = 0; + const stalled = new ReadableStream({ + pull() { + return new Promise(() => {}); + }, + cancel() { + cancels += 1; + }, + }); + const fixture = scopeWithMarkerBody(stalled); + let settled = false; - await expect( - runtimeFor(fixture.scope).onActivate(), - ).resolves.toBeTypeOf("number"); - expect(cancels).toBeGreaterThanOrEqual(1); - }, 10_000); + const activation = runtimeFor(fixture.scope) + .onActivate() + .finally(() => { + settled = true; + }); + // One read deadline per marker probe. + for (let probe = 0; probe < 4 && !settled; probe += 1) { + await vi.advanceTimersByTimeAsync(5_000); + } + + expect(settled).toBe(true); + await expect(activation).resolves.toBeTypeOf("number"); + expect(cancels).toBeGreaterThanOrEqual(1); + } finally { + vi.useRealTimers(); + } + }); it("cancels the body it refuses for a declared oversize", async () => { let cancels = 0;