Repository navigation
Show messages missed while disconnected, even after sending one #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
namespaceMarcello
wants to merge
3
commits into
basecamp:main
Choose a base branch
from
namespaceMarcello:catch-up-from-where-the-connection-dropped
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
test/system/catching_up_after_a_dropped_connection_test.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| require "application_system_test_case" | ||
|
|
||
| class CatchingUpAfterADroppedConnectionTest < ApplicationSystemTestCase | ||
| setup do | ||
| sign_in "jz@37signals.com" | ||
| join_room rooms(:designers) | ||
|
|
||
| using_session("Kevin") do | ||
| sign_in "kevin@37signals.com" | ||
| join_room rooms(:designers) | ||
| end | ||
| end | ||
|
|
||
| test "a message sent while the connection is down doesn't hide the ones missed before it" do | ||
| drop_connection | ||
| using_session("Kevin") { send_message "Missed while away" } | ||
| assert_no_message_text "Missed while away" | ||
|
|
||
| send_message "Sent while away" | ||
| restore_connection | ||
|
|
||
| assert_message_text "Missed while away", wait: 10 | ||
| assert_equal [ "Missed while away", "Sent while away" ], texts_from_while_away | ||
| end | ||
|
|
||
| test "messages missed or sent while the connection is down stay before one that arrives live as it comes back" do | ||
| drop_connection | ||
| using_session("Kevin") { send_message "Missed while away" } | ||
| send_message "Sent while away" | ||
| send_message "Sent again while away" | ||
| mark_message "Sent again while away" | ||
|
|
||
| # As if it arrived live once the connection was back, between the refresh's query and its answer. | ||
| execute_script <<~JS, dom_id(rooms(:designers), :messages), 1.minute.from_now.to_fs(:epoch) | ||
| document.getElementById(arguments[0]).insertAdjacentHTML("beforeend", | ||
| `<div class="message message--formatted" id="message_999999" data-message-id="999999" data-sort-value="${arguments[1]}"><div class="lexxy-content">Live while away</div></div>`) | ||
| JS | ||
| restore_connection | ||
|
|
||
| # The refresh brings the newest one again whatever happens, so its mark goes once the refresh is in. | ||
| assert_no_selector ".message[data-marked]", wait: 10 | ||
| assert_equal [ "Missed while away", "Sent while away", "Sent again while away", "Live while away" ], texts_from_while_away | ||
| end | ||
|
|
||
| test "messages missed while the connection is down show once it's back, and the ones shown before stay as they are" do | ||
| using_session("Kevin") do | ||
| send_message "Seen live" | ||
| # The refresh asks from the newest message's millisecond, so that one comes again whatever happens. | ||
| send_message "Seen live, the newest" | ||
| end | ||
| mark_message "Seen live" | ||
|
|
||
| drop_connection | ||
| using_session("Kevin") { send_message "Missed while away" } | ||
| assert_no_message_text "Missed while away" | ||
|
|
||
| restore_connection | ||
|
|
||
| assert_message_text "Missed while away", wait: 10 | ||
| assert_equal [ "Missed while away" ], texts_from_while_away | ||
| assert_selector ".message[data-marked]", text: "Seen live", count: 1 | ||
| end | ||
|
|
||
| private | ||
| # The server drops the connection, as it does when the user signs out elsewhere, and Chrome keeps it from coming | ||
| # back until restore_connection, while the rest of the page still reaches the server. | ||
| def drop_connection | ||
| page.driver.browser.execute_cdp "Network.enable" | ||
| page.driver.browser.execute_cdp "Network.setBlockedURLs", urls: [ "*/cable*" ] | ||
| users(:jz).reset_remote_connections | ||
| assert_no_selector "turbo-cable-stream-source[connected]", visible: false | ||
| end | ||
|
|
||
| def restore_connection | ||
| page.driver.browser.execute_cdp "Network.setBlockedURLs", urls: [] | ||
| # Action Cable tries again on its own schedule, several seconds apart. | ||
| assert_selector "turbo-cable-stream-source[connected]", count: 3, visible: false, wait: 30 | ||
| end | ||
|
|
||
| # A refresh that brings the message again replaces its element, and the mark with it. | ||
| def mark_message(text) | ||
| assert_message_text text | ||
| execute_script <<~JS, text | ||
| Array.from(document.querySelectorAll(".message")).find((message) => message.textContent.includes(arguments[0])).dataset.marked = "true" | ||
| JS | ||
| assert_selector ".message[data-marked]", text: text | ||
| end | ||
|
|
||
| def texts_from_while_away | ||
| all(".message .lexxy-content", text: "while away").map(&:text) | ||
| end | ||
|
|
||
| def assert_no_message_text(text) | ||
| assert_no_selector ".message__body", text: text | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, and reproduced: with a missed message, two sent while disconnected, and a live one put in the list before the refresh renders, the page ended with
[live, missed, sent, sent]. Addressed in 0514347: after a stream renders, every message it brought is put back in its place by sort value, which merges the missed and repeated ones into chronological order. The pagination boundary holds because this happens only while the list is at its end; on a merge with #369, doing it regardless fails its test of a refresh that misses more than a page, since paging then starts after the live message. The live-arrival test now includes a missed message, and fails on the previous commit and onmain.Written by Claude Code (AI assistant) on behalf of @namespaceMarcello, who directs this work.