e2e: Disconnect the previous ChatClient when the app re-initializes the SDK#6585
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
|
@CodeRabbit review |
✅ Action performedReview finished.
|
WalkthroughStartupActivity now runs initialization and navigation asynchronously, disconnects the existing ChatClient before reinitializing when configured, preserves existing routing paths, and finishes after coroutine work completes. ChangesStartup flow
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@stream-chat-android-compose-sample/src/e2e/java/io/getstream/chat/android/compose/sample/ui/StartupActivity.kt`:
- Around line 37-67: Add regression tests for StartupActivity covering a fresh
BASE_URL launch, a retry that awaits ChatClient.instance().disconnect before
ChatHelper.initializeSdk, and a notification launch without BASE_URL that
preserves the existing client. Verify each branch’s initialization and
navigation behavior using the existing test conventions and relevant
StartupActivity symbols.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 196def97-6ffd-443a-a76a-154c9a2c715f
📒 Files selected for processing (1)
stream-chat-android-compose-sample/src/e2e/java/io/getstream/chat/android/compose/sample/ui/StartupActivity.kt
SDK Size Comparison 📏
|
…s-chatclient-when-the-e2e-app-re
…s-chatclient-when-the-e2e-app-re
|



Goal
In the e2e flavor, every harness launch of
StartupActivitycallsChatHelper.initializeSdk, which builds a newChatClientwithout disconnecting the previous one. The app process survives across tests and retry attempts, so each launch added one more live client. In the 2026-07-21 nightly failure oftest_offlineMessageInTheMessageList, attempt 3 had three clients reconnecting and calling/syncat the same time, including against the previous attempts' mock servers. The extra clients contend on reconnect, the active client's/syncround trip stalls, andSyncManagerrestores channels only after the/syncresponse, so recovery lands outside the assertion window and the test fails all retries.Resolves AND-1321
Implementation
In the e2e
StartupActivity, when the launch carries aBASE_URLextra (every harness launch), disconnect the current client withChatClient.instance().disconnect(flushPersistence = true).await()before callingChatHelper.initializeSdk. Since the disconnect is a suspend call, theonCreatebody now runs insidelifecycleScope.launch.Notes on the paths that stay unchanged:
BASE_URL) has no suspension point, andlifecycleScopeusesDispatchers.Main.immediate, so that branch still runs synchronously insideonCreate.ChatHelper.disconnectUser()on purpose: it stopsSharedLocationService, andSharedLocationService.stop()cancels its coroutine scope permanently, which would break later attempts in the same process.Testing
This changes only the e2e flavor startup path, so the e2e suite is the verification:
bundle exec fastlane build_and_run_e2e_test) and confirm it still passes.RetryRuleretries) and check logcat: after the second launch there should be a[disconnect]log from the previous client, and only one client should reconnect and call/syncagainst the current mock server.test_offlineMessageInTheMessageListshould stop failing on retries with multiple clients alive.Summary by CodeRabbit