Skip to content

test(llc): de-flake queryChannels persistence verifies#2659

Open
xsahil03x wants to merge 1 commit into
masterfrom
fix/llc-deflake-queryChannels-tests
Open

test(llc): de-flake queryChannels persistence verifies#2659
xsahil03x wants to merge 1 commit into
masterfrom
fix/llc-deflake-queryChannels-tests

Conversation

@xsahil03x
Copy link
Copy Markdown
Member

@xsahil03x xsahil03x commented May 18, 2026

Summary

The two Client with connected user with persistence..queryChannels tests in client_test.dart waited only 50 ms past the 1 s debounce on ChannelClientState's persistence writes. The margin worked locally but raced the wall clock on the legacy_version_analyze CI runner — those tests have failed on every master commit since #2652.

#2652 wrapped queryChannelsOnline in InFlightCache.run, which adds a couple of microtasks of Future.sync + whenComplete overhead. Enough to shift the trailing-edge debounced updateChannelState past the 1050 ms window on slow CI — and to occasionally split a single channel's two rapid debounce triggers into two separate fires, depending on which side of the 1 s boundary they land.

Fix

  • await expectLater(...) (was fire-and-forget) so stream emissions are observed before the timing wait starts.
  • clearInteractions(persistence) after waiting past the setUp-induced debounce window, so calls scheduled by connectUser don't pollute the test's count.
  • Bump the post-emit delay from 1050 ms to 1500 ms — generous margin past the 1 s debounce on both updateChannelState and updateChannelThreads.

Test plan

  • flutter test packages/stream_chat/test/src/client/client_test.dart — all 155 tests pass.
  • Loop ×5, same. No flakes.
  • melos run analyze clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved reliability of persistence-enabled channel query tests by refining debounce timing and clearing mock state between test phases.

Review Change Stack

The two `Client with connected user with persistence`.`.queryChannels`
tests in `client_test.dart` waited only 50ms past the 1s debounce on
`ChannelClientState`'s persistence writes. That margin worked locally
but raced the wall clock on the legacy_version_analyze CI runner.

PR #2652 (coalesce queryChannels on flaky-network reconnects) wrapped
`queryChannelsOnline` in `InFlightCache.run`, adding a couple of
microtasks of `Future.sync` + `whenComplete` overhead — enough to
shift the trailing-edge debounce past the 1050ms window on slow CI.

- Await `expectLater` (was fire-and-forget) so stream emissions are
  observed before the timing wait starts.
- Discard interactions accumulated during `setUp` (`connectUser`
  schedules its own debounced persistence writes that would otherwise
  pollute the call count).
- Bump the post-emit delay to 1500ms so both the `updateChannelState`
  and `updateChannelThreads` debounces have safely fired before
  `verify().called(N)` runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3104fcd0-21b4-4c02-b83c-8cb1f013fda5

📥 Commits

Reviewing files that changed from the base of the PR and between d9d4ff4 and d9f1da9.

📒 Files selected for processing (1)
  • packages/stream_chat/test/src/client/client_test.dart

📝 Walkthrough

Walkthrough

Two queryChannels test cases in the Stream Chat client test suite are updated to properly synchronize with debounced persistence operations. Both tests now wait past the debounce window before clearing mock state and asserting, then wait again after assertions to ensure trailing debounced calls complete before verification.

Changes

Debounced Persistence Timing in queryChannels Tests

Layer / File(s) Summary
queryChannels persistence debounce timing adjustments
packages/stream_chat/test/src/client/client_test.dart
Both "should emit channels twice if persistence contains some channels" and "should never rethrow network call if persistence already emitted some channels" tests are updated to properly synchronize with debounced persistence operations by waiting past the debounce windows (1100ms before assertions, 1500ms after) and clearing mock interactions at the right time.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • Brazol

Poem

🐰 A timely hop through debounce delays,
These tests now wait the proper ways,
Clear the mocks, assert with care,
Then wait once more—timing squared!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test(llc): de-flake queryChannels persistence verifies' directly addresses the main change: fixing flaky queryChannels persistence tests by adjusting debounce timing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/llc-deflake-queryChannels-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.29%. Comparing base (d9d4ff4) to head (d9f1da9).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2659   +/-   ##
=======================================
  Coverage   65.29%   65.29%           
=======================================
  Files         423      423           
  Lines       26642    26642           
=======================================
  Hits        17397    17397           
  Misses       9245     9245           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants