Fix flaky 'broadcasts realm events' tests by waiting for both index events#4884
Conversation
The `broadcasts realm events` tests race on matrix sync ordering: the initiation and completion realm events are emitted without await ordering, so the completion event can become visible before the initiation event. The previous wait helper polled only for completion, then asserted on both events — when the initiation event hadn't synced yet, the assertion threw "Incremental index initiation event not found". Wait until BOTH events are visible before returning, and dump the realm events actually seen if either is still missing, so a future regression leaves a usable breadcrumb instead of a bare error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent failures in the realm-server test suite where incremental indexing realm events can arrive out-of-order via Matrix sync. It updates the “wait for incremental index event” helpers to only return once both the initiation (incremental-index-initiation) and completion (incremental) events are visible, and improves diagnostics when expectations fail.
Changes:
- Update incremental-index event waiting logic to require both initiation + completion events before proceeding.
- Add more informative error/timeout diagnostics showing what was observed when expected events are missing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/realm-server/tests/realm-endpoints-test.ts | Updates the local wait helper to require both initiation and completion index events; enhances failure logging. |
| packages/realm-server/tests/helpers/indexing.ts | Updates the shared wait helper to require both events and adds a detailed timeout message + improved failure diagnostics in assertions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
realm-endpoints-test.ts duplicated the helper with a 1s waitUntil default, which would re-introduce flakiness now that the wait requires two events. Import the shared helper (5s timeout + timeoutMessage) instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Host Test Results 1 files 1 suites 3h 0m 50s ⏱️ Results for commit 044a093. Realm Server Test Results 1 files ± 0 1 suites ±0 9m 8s ⏱️ + 1m 44s Results for commit 044a093. ± Comparison against earlier commit d91d013. |
Summary
broadcasts realm eventstests incard-source-endpoints-test.tsandrealm-endpoints-test.tsintermittently fail withIncremental index initiation event not found(seen in run 26105757476).incremental-index-initiationandincrementalevents are visible before returning. Same fix applied in both copies of the helper.Test plan
card source DELETE request > public writable realm > broadcasts realm eventsand the sibling cases should pass consistently.[expectIncrementalIndexEvent] missing event(s) …line (or the timeout message variant) listing what was visible, so we can distinguish a real missing-event bug from sync ordering.🤖 Generated with Claude Code