Skip to content

test(chat): tear the coordinator down however a test ends - #1512

Merged
bmc08gt merged 1 commit into
code/cashfrom
test/chat-coordinator-teardown-guards
Sep 21, 2026
Merged

bmc08gt merged 1 commit into
code/cashfrom
test/chat-coordinator-teardown-guards

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

A coordinator test that failed its assertion hung the run instead of reporting the failure.

RealChatCoordinator.onUserLoggedIn ends with startHeartbeat { syncFeeds() }, a while (true) of delays on the coordinator's own CoroutineScope. That scope is not the test's backgroundScope, so it outlives the test body, and runTest drains the scheduler once the body returns. These tests called coordinator.teardown() as a bare last statement, so an assertion that threw skipped it and left that loop advancing virtual time with nothing to stop it.

Each body now runs inside a tornDown helper that tears down in a finally.

Evidence

Same deliberate break (exactly = 1 to exactly = 99) in ViewerStateStreamTest, run twice:

Arrangement Result
Before this change still spinning when killed at 240s; no failure reported
After this change fails in 14s, naming all three affected tests

Module suite green at 13s.

Scope

25 tests across four files. GroupChatRoutingTest and ChatHistoryHydrationTest already used this shape and document the hazard in KDoc — this brings the rest onto the same footing rather than inventing a pattern.

ChatCoordinatorTeardownTest is deliberately untouched: it calls teardown() as the subject under test and never logs in, so no heartbeat is running. The one deliberate mid-body teardown() in ChatCoordinatorEventsTest's re-login test is also preserved — only its trailing call became the finally.

Tests only; no production code.

Why separately from #1511

Found while debugging a hang in a new test on that branch. It is a pre-existing hazard in tests unrelated to that fix, so it reviews better on its own.

A coordinator test that failed its assertion hung the run instead of reporting
the failure. Logging in starts a heartbeat that is a `while (true)` of delays on
the coordinator's own scope rather than the test's `backgroundScope`, and
`runTest` drains the scheduler once the body returns. These tests called
`coordinator.teardown()` as a bare last statement, so an assertion that threw
skipped it and left that loop advancing virtual time with nothing to stop it.

Wrap each body in a `tornDown` helper that tears down in a `finally`. Breaking
one assertion in ViewerStateStreamTest shows the difference: unwrapped it was
still spinning when killed at 240s with nothing reported, wrapped it fails in
14s naming all three affected tests.

GroupChatRoutingTest and ChatHistoryHydrationTest already did this and document
why; this brings the remaining four files onto the same footing.
ChatCoordinatorTeardownTest is left alone — it calls teardown() as its subject
and never logs in, so no heartbeat is running.
@bmc08gt bmc08gt self-assigned this Sep 21, 2026
@github-actions github-actions Bot added the type: test Test additions or improvements label Sep 21, 2026
@bmc08gt
bmc08gt merged commit 351b6fc into code/cash Sep 21, 2026
3 checks passed
@bmc08gt
bmc08gt deleted the test/chat-coordinator-teardown-guards branch September 23, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: test Test additions or improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant