Skip to content

UTS: repair realtime/unit fixtures that cannot reach their condition - #590

Open
owenpearson wants to merge 6 commits into
mainfrom
fix/uts-realtime-unit-unreachable-fixtures
Open

owenpearson wants to merge 6 commits into
mainfrom
fix/uts-realtime-unit-unreachable-fixtures

Conversation

@owenpearson

@owenpearson owenpearson commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Fixes the uts/realtime/unit fixtures reported in #544, which set up a condition they can't reach, and the second-mock problem in RTN7e reported in #571.

connectionStateTtl isn't a ClientOptions field. DF1a gives it a 120 s default, and CD2f/RTN21 let the CONNECTED message's connectionDetails override it. So a test can shorten it only by sending it in CONNECTED. That recipe is already documented at RTP11d in realtime_presence_get.md, so no mock change is needed. The fixes follow one rule:

  • Tests that never connect have no CONNECTED to shorten the TTL. They advance fake time past the 120 s default in a loop. This matches RTN14e, which names the default connectionStateTtl.
  • Tests that connect first use one mock. It accepts the first attempt with a CONNECTED carrying connectionStateTtl: 5000 and refuses every later attempt. The test drops the transport and advances fake time until the connection is SUSPENDED.

Corrections to #544

  • The count is 13, not 10. The title counts six TTL tests and four never-connected tests. §1 actually lists seven TTL tests (RTN25, RTN14e, RTL6c4, RTN7e, RTL4b, RTP5f, RTL11), and §2 (RTN24) and §3 (RTP5a) add one each.
  • RTS4a is already fixed. Make Channels#release error on non-terminal channel states (RTS4b-e) #557 replaced it with a test that installs a mock and connects, and Align channels_collection UTS with RTS4c-e numbering and code 90011 #563 renumbered that test to RTS4d release-after-detach-1. This PR doesn't touch channels_collection.md.
  • No mock change is needed. §1 proposes giving the mock a way to deliver a short connectionStateTtl, but respond_with_success(ProtocolMessage(..., connectionDetails: ConnectionDetails(connectionStateTtl: 5000))) already does this.
  • RTN25 doesn't connect first. §1 proposes that its mock accept one connection before refusing. That would turn it into an RTN15 test, while RTN25 cites RTN14e, which names the default TTL. It advances past 120 s instead.
  • RTN24 keeps its clientId. §2 proposes dropping the clientId from the second CONNECTED. This PR sends the original value again instead, so an absent clientId can't be read as clearing it.

Per-fixture changes

Never connect: advance past the 120 s default

  1. realtime/unit/RTN25/error-reason-suspended-2 (connection/error_reason_test.md). Removed the local DEFAULT_CONNECTION_STATE_TTL = 5000, which nothing passed to the SDK. It now loops ADVANCE_TIME(10000) until SUSPENDED, up to 150 s.
  2. realtime/unit/RTN14e/disconnected-to-suspended-0 (connection/connection_open_failures_test.md). Same change. The requirement line now says "default connectionStateTtl".
  3. realtime/unit/RTL6c4/fails-conn-suspended-0 (channels/channel_publish.md). Removed the non-existent ClientOptions(connectionStateTtl: 5000). The loop now advances 10 s per step instead of 2 s, so it gets past 120 s.
  4. realtime/unit/RTL4b/fails-connection-suspended-2 (channels/channel_attach.md). Removed channelRetryTimeout: 100, which governs channels (RTL13b). Added enable_fake_timers(), which the test lacked, and the 120 s advance loop. Also moved install_mock before the client is built, as everywhere else in the suite.

Connect first: short TTL from CONNECTED

  1. realtime/unit/RTN7e/pending-fail-suspended-0 (channels/channel_publish.md). Removed ClientOptions(connectionStateTtl: 5000). The test used to bind mock_ws to a second mock and call install_mock again mid-test, so simulate_disconnect() targeted a mock with no connection (channel_publish.md: RTN7e pending-fail-suspended-0 replaces mock_ws mid-test, so simulate_disconnect() targets a mock with no connection #571). It now uses one mock that accepts the first attempt with connectionStateTtl: 5000 and refuses the rest, as channel_publish.md: RTN7e pending-fail-suspended-0 replaces mock_ws mid-test, so simulate_disconnect() targets a mock with no connection #571 proposes.
  2. realtime/unit/RTP5f/suspended-maintains-presence-map-0 (presence/realtime_presence_channel_state.md). The test dropped the transport and awaited a SUSPENDED channel straight away. A transport drop leaves the connection DISCONNECTED (RTN15a), and RTL3c suspends channels only from a SUSPENDED connection. The mock also accepted every reconnect. It now uses the counting mock with connectionStateTtl: 5000, fake timers and the advance loop.
  3. realtime/unit/RTL11/queued-presence-fail-suspended-1 (same file). Same change as RTP5f.

Other fixtures from #544

  1. realtime/unit/RTN24/connection-details-override-2 (connection/update_events_test.md). The second CONNECTED now sends clientId: "client-original" again instead of changing it to "client-updated". RTN24 overrides operational parameters; it doesn't change the connection's identity. The changed serverId, maxIdleInterval, connectionStateTtl and maxMessageSize still exercise RTN24.
  2. realtime/unit/RTP5a/detached-clears-presence-maps-0 (presence/realtime_presence_channel_state.md). On a DETACHED channel, presence.get(waitForSync: false) re-attaches it (RTP11e → RTL33b), and the mock answered every ATTACH with a SYNC carrying alice, so a conforming SDK returned one member. The mock now sends the SYNC only for the first ATTACH. It answers the re-attach with ATTACHED (with HAS_PRESENCE) and no SYNC, so the read-back is the map DETACHED left. If an SDK didn't clear the map, it still holds alice and the test fails. The read-back is now AWAITed, since it attaches.
  3. realtime/unit/RTS3c1/error-reattach-params-0 (channels/channel_options.md). Installs a mock that answers ATTACH and connects before attaching. Without a connection, RTL4i parks the attach in ATTACHING.
  4. realtime/unit/RTS3c1/error-reattach-modes-1 (same file). The test only had the comment # Put channel in attaching state (implementation detail). It now installs a mock that leaves ATTACH unanswered, connects, calls attach(), and waits for ATTACHING.
  5. realtime/unit/RTL16a/triggers-reattach-0 (same file). Same mock and connection as RTS3c1-0. Its assertion that the channel passes through ATTACHING is unchanged; realtime/unit/channels: seven tests expect behaviour the features spec doesn't define, or rely on the client not reconnecting #579 §2 covers it.

channel_options.md also gets the ## Mock WebSocket Infrastructure section that the other channels/ files have.

Same defect, not listed in #544

  1. realtime/unit/RTP11d/get-suspended-errors-default-0 and realtime/unit/RTP11d/get-suspended-no-wait-returns-1 (presence/realtime_presence_get.md). These are the tests under the note that documents the CONNECTED-TTL recipe, and they have RTP5f's defect. They already send connectionStateTtl: 5000, but their mock accepts every reconnect and they await SUSPENDED with no fake time. They now follow the rest of their own note: the counting mock, disconnectedRetryTimeout: 500, fake timers and the advance loop. This is in a separate commit, so it can be dropped if it's out of scope here.

Not changed

Closes #544
Closes #571

🤖 Generated with Claude Code

owenpearson and others added 6 commits November 27, 2026 13:51
…connect

RTN25 error-reason-suspended-2, RTN14e disconnected-to-suspended-0,
RTL6c4 fails-conn-suspended-0 and RTL4b fails-connection-suspended-2
refuse every connection attempt and then wait for a SUSPENDED
connection. No CONNECTED message reaches the client, so the TTL in
force is the DF1a default of 120 s, which RTN14e names. The tests tried
to shorten it with a local variable (RTN25, RTN14e), a ClientOptions
field that does not exist (RTL6c4), or channelRetryTimeout, which
governs channels (RTL4b). None of these reaches the SDK.

Each test now advances fake time past 120 s in a loop. RTL4b also
enables fake timers and installs its mock before building the client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nect first

RTN7e pending-fail-suspended-0, RTP5f suspended-maintains-presence-map-0
and RTL11 queued-presence-fail-suspended-1 connect, drop the transport,
and wait for a SUSPENDED connection or channel. None of them could get
there:

- RTN7e passed connectionStateTtl as a ClientOptions field, which does
  not exist. It also re-bound mock_ws to a new mock that had never
  accepted a connection, so simulate_disconnect() targeted a mock with
  no active connection, and the second install_mock was not guaranteed
  to reach a client that was already connected.
- RTP5f and RTL11 dropped the transport and awaited a SUSPENDED channel
  straight away. A transport drop leaves the connection DISCONNECTED
  (RTN15a); RTL3c suspends channels only from a SUSPENDED connection.
  Their mocks also accepted every reconnection attempt, and neither
  test used fake timers.

Each now uses one mock that accepts the first attempt with a CONNECTED
whose connectionDetails carry connectionStateTtl: 5000, and refuses the
rest, then advances fake time until the connection is SUSPENDED. This
is the recipe already documented at RTP11d in realtime_presence_get.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RTP11d get-suspended-errors-default-0 and get-suspended-no-wait-returns-1
have the defect RTP5f had: they drop the transport and await a
SUSPENDED channel at once, with a mock that accepts every reconnection
attempt and no fake timers. The client reconnects, so the channel never
becomes SUSPENDED. Both already send connectionStateTtl: 5000 in
CONNECTED, as the note above them describes, but do not carry out the
rest of that note.

Each now refuses every attempt after the first and advances fake time
until the connection is SUSPENDED, following the note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RTN24 connection-details-override-2 sent a second CONNECTED whose
connectionDetails changed clientId from "client-original" to
"client-updated", then asserted the connection was still CONNECTED.
The test's own requirement line lists the details RTN24 overrides as
operational parameters (maxIdleInterval, connectionStateTtl,
maxMessageSize, serverId). Re-identifying an already-identified
connection is not one of them, and whether an SDK should accept it is
a separate question under RSA7b3 that the fixture should not settle.

The second CONNECTED now repeats the original clientId. The other
changed details still exercise RTN24.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RTP5a detached-clears-presence-maps-0 detaches the channel and then
reads the presence map with presence.get(waitForSync: false), expecting
no members. On a DETACHED channel get runs ensure-active-channel
(RTP11e), which re-attaches it (RTL33b); waitForSync: false only skips
waiting for the SYNC. The mock answered every ATTACH with a SYNC
carrying alice, so a conforming SDK returned one member.

The mock now sends the SYNC only for the first ATTACH, and answers the
re-attach with ATTACHED alone, so get returns the map DETACHED left.
The read-back is also awaited, since it attaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RTS3c1 error-reattach-params-0 and RTL16a triggers-reattach-0 build a
client with autoConnect: false, install no mock, never connect, and
then await channel.attach() and assert ATTACHED. Per RTL4i the attach
leaves the channel ATTACHING until the connection is CONNECTED, so the
await never returns, and with no mock nothing would answer the ATTACH.
RTS3c1 error-reattach-modes-1 needs an ATTACHING channel and only says
"Put channel in attaching state (implementation detail)".

Each setup now installs a mock and connects. The two attached tests
answer every ATTACH; error-reattach-modes-1 leaves its ATTACH
unanswered and waits for ATTACHING. The file gains the Mock WebSocket
Infrastructure section its siblings have.

RTL16a's assertion that the channel passes through ATTACHING is left
as it is; that is #579.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
staging/pull/590 — 5e7e801a Deployed Nov 27, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant