e2e: Wait for the WebSocket disconnect before the participant sends a message#6586
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
|
@CodeRabbit review |
✅ Action performedReview finished.
|
SDK Size Comparison 📏
|
WalkthroughOffline E2E tests now wait for confirmed WebSocket disconnection after backgrounding. ChangesOffline WebSocket synchronization
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 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-e2e-test/src/main/kotlin/io/getstream/chat/android/e2e/test/robots/BackendRobot.kt`:
- Around line 135-153: Update waitForWebSocketDisconnection to ensure each
mockServer.getRequest("ws/status") poll has a timeout bounded by the remaining
timeoutMillis, configuring or passing a bounded HTTP client/call timeout through
the MockServer request path. Preserve the existing polling interval,
disconnected-status return, and failure message while preventing a stalled
request from exceeding the method deadline.
🪄 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 Plus
Run ID: 188f86f5-1893-4487-8268-4d8d17b50b61
📒 Files selected for processing (2)
stream-chat-android-compose-sample/src/androidTestE2eDebug/kotlin/io/getstream/chat/android/compose/tests/MessageListTests.ktstream-chat-android-e2e-test/src/main/kotlin/io/getstream/chat/android/e2e/test/robots/BackendRobot.kt
|



Goal
test_offlineMessageInTheMessageListhas a flake mode where the participant's message is delivered live while the test is taking the app offline. The SDK keeps the WebSocket open for a short period after the app goes to background (the socket is only closed when the delayed lifecycle stop reachesChatSocketStateService.onStop()), andsvc data disabledoes not close established sockets immediately. So themessage.newevent can arrive over the still-open socket, the message is stored locally and shown while offline, and the assert "user does not observe a new message from participant" fails.This change removes the race by waiting until the client socket is actually disconnected before the participant sends the message.
Depends on GetStream/stream-chat-test-mock-server#49, which must merge first because the e2e CI clones the mock server
mainbranch.Resolves AND-1325
Implementation
BackendRobot.waitForWebSocketDisconnection()instream-chat-android-e2e-testpolls the mock server's newGET /ws/statusendpoint until the server reports the socket as closed.test_offlineMessageInTheMessageListandtest_offlineRecoveryWithinSessioncall it after backgrounding the app, before the participant sends. Ordering is now decided on the server: once it reportsconnected: false, its socket handle isnil, so the participant message is only stored and gets delivered on reconnect.test_offlineRecoveryWithinSessionis included because it has the same race. It passes either way today, but without the wait the message can be delivered live before the socket closes, so the test can pass without exercising the recovery path it is meant to cover.No UI changes.
Testing
bundle exec ruby driver.rb../gradlew :stream-chat-android-compose-sample:assembleE2eDebug :stream-chat-android-compose-sample:assembleE2eDebugAndroidTest, thenadb install -rboth.adb shell am instrument -w -e class 'io.getstream.chat.android.compose.tests.MessageListTests#test_offlineMessageInTheMessageList' io.getstream.chat.android.compose.sample.e2etest.debug.test/io.qameta.allure.android.runners.AllureAndroidJUnitRunner.logs/test_offlineMessageInTheMessageList_*.log), verify the order:GET /ws/statusreturnsconnected: false, thenPOST /participant/message, then the message is delivered after reconnect through/syncand the channel query.Both tests pass locally with this flow.
spotlessCheckanddetektpass on the touched modules.Summary by CodeRabbit