testing/cross_backend/ws_connection_cap.ts

Cross-backend parity suite for the per-account WebSocket connection cap over a real upgrade.

Both spines bound an account's concurrent WebSocket connections (BackendWebsocketTransport's max_connections_per_account on the TS side, the Rust fuz_realtime ConnectionRegistry on the other; both default to DEFAULT_MAX_CONNECTIONS_PER_ACCOUNT) with the same policy: evict-oldest — a connection past the cap is always admitted, and the account's oldest is closed with WS_CLOSE_CONNECTION_LIMIT and the reason connection limit. A client reads that close as "superseded": closed until the user acts, not revoked and not reconnecting (FrontendWebsocketClient.superseded). The code, the reason, and which socket closes are therefore wire contract, and this suite is the pin that runs on both. Two cases:

  • the oldest is superseded, and it is not a revocation — on one session, opening one socket past the cap closes exactly the first with the connection-limit code and reason; every other socket, the newest included, stays open and still dispatches. The session then upgrades again, which a revoked session could not — and that upgrade supersedes the next-oldest in turn.
  • a closed connection frees its slot — one socket held open while a cap's worth of others open and close in sequence is never evicted. A backend that leaks closed connections in its registry counts them toward the cap and closes the held socket, which is what this catches.

Sockets open in sequence, each answering a heartbeat before the next opens (create_admitted_ws_transport), so the backend registered them in that order and "oldest" names the same socket on both spines (an upgrade answers its handshake before the connection is registered and admitted, so the handshake alone doesn't order them).

Consumer-agnostic, like describe_cross_process_ws_tests: it drives only the heartbeat protocol action, present on every WS endpoint. Gated on capabilities.ws; cross-process only (create_ws_transport needs a real bound socket). Each case opens more than a cap's worth of real sockets, which is why it's a separate call rather than more cases on the WS round-trip suite.

view source

Declarations
#

2 declarations

describe_ws_connection_cap_cross_tests
#

WsConnectionCapCrossTestOptions
#

testing/cross_backend/ws_connection_cap.ts view source

WsConnectionCapCrossTestOptions import type {WsConnectionCapCrossTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/ws_connection_cap.js';

Options for the WebSocket connection-cap parity suite.

setup_test

Per-test fixture producer (default_cross_process_setup(handle)). Every socket in a case upgrades with the fresh-per-test keeper's session cookies, so they all land on one account.

type (): Promise<TestFixtureBase>

readonly
returns Promise<TestFixtureBase>

capabilities

Backend capability flags; every case gates on capabilities.ws.

type BackendCapabilities

readonly

base_url

Base URL the backend is reachable at (e.g. http://localhost:1178).

type string

readonly

ws_path

WebSocket endpoint path on the backend (e.g. /api/ws).

type string

readonly

origin?

Origin for the upgrades. Defaults to base_url.

type string

readonly

max_connections_per_account?

The backend's per-account connection cap, which each case opens past. Defaults to DEFAULT_MAX_CONNECTIONS_PER_ACCOUNT, the cap both spines apply unless overridden; pass the consumer's value when it sets one, or null (a backend with the cap disabled) to skip the cases.

type number | null

readonly

Depends on
#