test(realtime): WebSocket 구독별 초당 event 상한을 테스트로 고정한다

문제
WebSocket 연결은 구독마다 1초 창에 maxEventsPerSecond(256, server가
알린 값과 작은 쪽)를 넘는 event가 오면 EVENT_RATE_EXCEEDED recovery를
요청하고 QUEUE_OVERFLOW로 닫는다. 이를 확인하는 테스트가 없어 검사를
꺼도 모든 테스트가 통과한다(리뷰 변이 R7, 두 라운드째). 설계 11절
상한표에도 행이 없다.

고른 방법
- 상한을 2로 낮춘 연결에서 2개 → 1초 뒤 2개(열림 유지) → 1개 더(닫힘,
  EVENT_RATE_EXCEEDED)를 보내는 테스트 1건을 더한다. 창 초기화와 상한
  값 출처까지 한 테스트가 본다.
- 설계 11절 상한표에 행 하나를 더한다.

위험·한계
- 동작은 바꾸지 않았다. 실제 서버 부하로는 확인하지 않았다.

검증
- 새 테스트 통과(websocket-connection 24건).
- 변이 3건 모두 검출: 상한 검사 끄기(R7), 1초 창 초기화 삭제, 협상된
  상한 대신 256 고정.
- 바꾼 파일 eslint 통과.

Refs: docs/reviews/2026-11-03-maturity-review/04-adapters-realtime.md 2절 1101/04-03
This commit is contained in:
DongHyeonka
2026-11-04 20:34:12 +09:00
parent 0cc2553381
commit 3bc690d3fb
2 changed files with 58 additions and 0 deletions
@@ -1837,6 +1837,7 @@ authoritative query data를 덮지 않는다.
| reorder buffer | 기본 0; 선택 시 64 event, 2초 |
| WebSocket outbound queued bytes | 256 KiB |
| WebSocket outbound queued messages | 128 |
| WebSocket 구독별 event rate | 1초 창마다 256 event. client 상한과 server가 알린 `maxEventsPerSecond` 중 작은 값. 넘으면 그 구독에 `EVENT_RATE_EXCEEDED` recovery를 요청하고 `QUEUE_OVERFLOW`로 연결을 닫는다(1101/04-03, `websocket-connection.ts` `processEvent`) |
| reconnect attempts | 연속 10회 또는 5분 |
| reconnect max delay | 60초 |
| aborted reconnect task drain | 2초 고정; 구현 절대 최대 30초 |
@@ -650,6 +650,63 @@ describe("WebSocket connection generation", () => {
releaseFirst?.();
});
// 1101/04-03. Each subscription may apply at most maxEventsPerSecond events
// in a one-second window (the lower of the client ceiling and the server's
// advertised limit). One more requests recovery and closes the generation.
it("closes a subscription that exceeds its per-second event ceiling", async () => {
const runtime = setup({ ceilings: { maxEventsPerSecond: 2 } });
await openConnection(runtime);
runtime.connection.subscribe({
subscriptionId: "subscription.0001",
streamId: "orders.v1",
scopeBinding: "scope.0001",
stateBearing: true,
checkpoint: {
streamEpoch: "stream-epoch.0001",
lastAppliedSequence: "10",
cursor: "cursor.0010",
},
});
runtime.socket.message(
serverFrame({
type: "SUBSCRIBED",
subscriptionId: "subscription.0001",
streamEpoch: "stream-epoch.0001",
acceptedCursor: "cursor.0010",
nextExpectedSequence: "11",
}),
);
await flush();
const event = serverFrame({
type: "EVENT",
subscriptionId: "subscription.0001",
envelope: {
protocol: "REALTIME_EVENT_V1",
streamId: "orders.v1",
},
});
const deliver = async (count: number) => {
for (let index = 0; index < count; index += 1) {
runtime.socket.message(event);
for (let turn = 0; turn < 5; turn += 1) await flush();
}
};
await deliver(2);
runtime.clock.current += 1_000;
await deliver(2);
expect(runtime.onEvent).toHaveBeenCalledTimes(4);
expect(runtime.connection.inspect().status).toBe("OPEN");
await deliver(1);
expect(runtime.onEvent).toHaveBeenCalledTimes(4);
expect(runtime.connection.inspect().status).toBe("CLOSED");
expect(runtime.recoveries).toContainEqual({
subscriptionId: "subscription.0001",
reason: "EVENT_RATE_EXCEEDED",
});
});
it("rejects an event routed through the wrong logical subscription", async () => {
const runtime = setup();
await openConnection(runtime);