diff --git a/tests/unit/browser-rpc/browser-rpc-remediation.test.ts b/tests/unit/browser-rpc/browser-rpc-remediation.test.ts index 7167788f..8048d718 100644 --- a/tests/unit/browser-rpc/browser-rpc-remediation.test.ts +++ b/tests/unit/browser-rpc/browser-rpc-remediation.test.ts @@ -377,6 +377,19 @@ describe("RPC-RR-04 transport results and frames are exactly decoded", () => { }); }); +/** + * 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, a test + * passes that bound instead of sleeping through it. The operations' own 25 ms + * deadlines are below the cap and unchanged. Every stream test that ends + * without a positive receipt takes it, so none sleeps a real second. + */ +const cappedClock: ClockPort = Object.freeze({ + now: () => systemClock.now(), + sleep: (milliseconds: number, signal?: AbortSignal) => + systemClock.sleep(Math.min(milliseconds, 30), signal), +}); + /** * RPC-RR-01. A bare `AsyncIterable` gave the runtime no way to cancel the * physical stream or to learn when it actually closed, so a timed-out call left @@ -395,6 +408,7 @@ describe("RPC-RR-01 server stream leases and the DRAINING fence", () => { mappers: MAPPERS, requestEncoders: { RpcResourceStreamRequestEncoder: STREAM_ENCODER }, transports: { CONNECT_REFERENCE_STREAM: probe.transport }, + clock: cappedClock, }); const results = await collect( @@ -418,6 +432,7 @@ describe("RPC-RR-01 server stream leases and the DRAINING fence", () => { mappers: MAPPERS, requestEncoders: { RpcResourceStreamRequestEncoder: STREAM_ENCODER }, transports: { CONNECT_REFERENCE_STREAM: probe.transport }, + clock: cappedClock, }); const stream = runtime.bindServerStream( "WATCH_RPC_RESOURCES", @@ -541,18 +556,6 @@ 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); @@ -598,6 +601,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",