Skip to content

Commit 09b179e

Browse files
Make slow RPC ack threshold configurable in tests
- Add a test-only setter for the slow RPC ack timer - Use a shorter threshold in wsTransport coverage to keep the test fast
1 parent 7cf36ba commit 09b179e

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

apps/web/src/rpc/requestLatencyState.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { appAtomRegistry } from "./atomRegistry";
55

66
export const SLOW_RPC_ACK_THRESHOLD_MS = 15_000;
77
export const MAX_TRACKED_RPC_ACK_REQUESTS = 256;
8+
let slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS;
89

910
export interface SlowRpcAckRequest {
1011
readonly requestId: string;
@@ -56,12 +57,12 @@ export function trackRpcRequestSent(requestId: string, tag: string): void {
5657
startedAt: new Date(startedAtMs).toISOString(),
5758
startedAtMs,
5859
tag,
59-
thresholdMs: SLOW_RPC_ACK_THRESHOLD_MS,
60+
thresholdMs: slowRpcAckThresholdMs,
6061
};
6162
const timeoutId = setTimeout(() => {
6263
pendingRpcAckRequests.delete(requestId);
6364
appendSlowRpcAckRequest(request);
64-
}, SLOW_RPC_ACK_THRESHOLD_MS);
65+
}, slowRpcAckThresholdMs);
6566

6667
pendingRpcAckRequests.set(requestId, {
6768
request,
@@ -119,9 +120,14 @@ function evictOldestPendingRpcRequestIfNeeded(): void {
119120
}
120121

121122
export function resetRequestLatencyStateForTests(): void {
123+
slowRpcAckThresholdMs = SLOW_RPC_ACK_THRESHOLD_MS;
122124
clearAllTrackedRpcRequests();
123125
}
124126

127+
export function setSlowRpcAckThresholdMsForTests(thresholdMs: number): void {
128+
slowRpcAckThresholdMs = thresholdMs;
129+
}
130+
125131
export function useSlowRpcAckRequests(): ReadonlyArray<SlowRpcAckRequest> {
126132
return useAtomValue(slowRpcAckRequestsAtom);
127133
}

apps/web/src/wsTransport.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
__resetClientTracingForTests,
66
configureClientTracing,
77
} from "./observability/clientTracing";
8-
import { getSlowRpcAckRequests, resetRequestLatencyStateForTests } from "./rpc/requestLatencyState";
8+
import {
9+
getSlowRpcAckRequests,
10+
resetRequestLatencyStateForTests,
11+
setSlowRpcAckThresholdMsForTests,
12+
} from "./rpc/requestLatencyState";
913
import {
1014
getWsConnectionStatus,
1115
getWsConnectionUiState,
@@ -292,6 +296,8 @@ describe("WsTransport", () => {
292296
});
293297

294298
it("marks unary requests as slow until the first server ack arrives", async () => {
299+
const slowAckThresholdMs = 25;
300+
setSlowRpcAckThresholdMsForTests(slowAckThresholdMs);
295301
const transport = new WsTransport("ws://localhost:3020");
296302

297303
const requestPromise = transport.request((client) =>
@@ -320,7 +326,7 @@ describe("WsTransport", () => {
320326
tag: WS_METHODS.serverUpsertKeybinding,
321327
},
322328
]);
323-
}, 5_000);
329+
}, 1_000);
324330

325331
socket.serverMessage(
326332
JSON.stringify({
@@ -343,7 +349,7 @@ describe("WsTransport", () => {
343349
expect(getSlowRpcAckRequests()).toEqual([]);
344350

345351
await transport.dispose();
346-
}, 10_000);
352+
}, 5_000);
347353

348354
it("sends unary RPC requests and resolves successful exits", async () => {
349355
const transport = new WsTransport("ws://localhost:3020");

0 commit comments

Comments
 (0)