Skip to content

Wrap SimulateScenario to test server-initiated reconnect/leave paths#197

Draft
alan-george-lk wants to merge 3 commits into
mainfrom
alan/connect-disconnect-analysis
Draft

Wrap SimulateScenario to test server-initiated reconnect/leave paths#197
alan-george-lk wants to merge 3 commits into
mainfrom
alan/connect-disconnect-analysis

Conversation

@alan-george-lk

Copy link
Copy Markdown
Collaborator

What & why

While mapping every connect/disconnect path in the SDK, the one glaring coverage gap was the server-initiated paths — onReconnecting/onReconnected and server-driven onDisconnected had zero tests, because nothing on the client could drive them without a live server plus out-of-band server-admin calls (delete room / remove participant).

The Rust core already exposes a chaos/E2E hook for exactly this — SimulateScenario — at the FFI boundary (SimulateScenarioRequest → async SimulateScenarioCallback), but the C++ layer never surfaced it. This PR wraps it and uses it to close the reconnect coverage gap, and adds a written analysis of all connect/disconnect paths.

What changed

New SimulateScenario API (mirrors the existing disconnect() async pattern layer-for-layer):

  • SimulateScenario public enum in room_event_types.h (9 variants: SignalReconnect, NodeFailure, ServerLeave, Migration, ForceTcp/Tls, FullReconnect, DisconnectSignalOnResume, Speaker), documented as a testing/chaos hook
  • toProto(SimulateScenario) in room_proto_converter.cpp
  • FfiClient::simulateScenarioAsync(room_handle, scenario) + the kSimulateScenario case in ExtractAsyncId
  • Room::simulateScenario(SimulateScenario) — grabs the handle under lock, throws if not connected, blocks on the FFI callback, returns whether it was accepted (same deadlock caveat as disconnect())

Tests:

  • unit: SimulateScenarioOnDisconnectedRoomThrows (no server needed — verifies the not-connected guard)
  • integration (test_room_reconnect.cpp): SignalReconnectResumesSession and FullReconnectReestablishesSession assert onReconnectingonReconnected; ServerLeaveDisconnects asserts a server-initiated onDisconnected

Docs: docs/connection-lifecycle.md — full matrix of client- and server-initiated connect/disconnect paths, their interactions, and per-path test coverage, updated to reflect the new coverage.

Reviewer notes

  • Not built/run here. The changed/new files were syntax-checked (-fsyntax-only) against the real generated protobuf headers from a local build-debug tree using that build's exact flags — all pass, confirming the proto symbol names match the pinned submodule. A full build + integration run against a live server (LIVEKIT_URL/LIVEKIT_TOKEN_A) is still needed to confirm runtime behavior.
  • ServerLeave semantics (disconnect vs. reconnect) were inferred from the FFI proto comments, not observed — worth confirming when the integration suite runs.
  • Public vs. test-only: simulateScenario is exposed on the public Room API (matching rust-sdks and client-sdk-js), documented as testing/chaos-only. Happy to move it behind a test-only seam (e.g. gated on LIVEKIT_TEST_ACCESS) if preferred.
  • Separately noticed src/room_event_converter.cpp appears to be dead code (not in CMake, includes a nonexistent header, stub toDisconnectReason returning Unknown) — left out of this PR; flagged for a follow-up.

🤖 Generated with Claude Code

alan-george-lk and others added 3 commits July 6, 2026 21:08
…coverage

Maps all client-initiated (disconnect(), destructor, shutdown, signals)
and server-initiated (kDisconnected, kEos, reconnect, FFI panic)
connection paths, their interactions, and the current unit/integration
test coverage for each, including identified gaps.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… paths

Adds the Rust SimulateScenario FFI hook to the lifecycle analysis: enum
mapping, its status (supported by the core but unwrapped in C++), and how
it complements a fake event injector for closing the server-initiated
coverage gaps (S1/S3).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds Room::simulateScenario(SimulateScenario) over a new
FfiClient::simulateScenarioAsync, a public SimulateScenario enum, and the
proto mapping — mirroring the disconnect() async pattern. This surfaces the
Rust core's chaos/reconnect hook so tests can drive the previously
zero-coverage server-initiated paths in-band, without server-admin calls.

Tests:
- unit: simulateScenario on a disconnected room throws (no server needed)
- integration: SignalReconnect and FullReconnect drive onReconnecting/
  onReconnected; ServerLeave drives a server-initiated onDisconnected

Updates docs/connection-lifecycle.md coverage matrix accordingly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant