-
Notifications
You must be signed in to change notification settings - Fork 4
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
Restart closed websocket if still subscribed #1373
Conversation
WalkthroughThe pull request introduces modifications to the WebSocket service implementation in both test and service files. The changes focus on improving event handling and subscription resilience. In the test file, the WebSocket service test suite is updated with more precise spy tracking and event monitoring. In the service implementation, a new mechanism is added to automatically re-establish subscriptions when resources exist after a connection closure. Changes
Sequence DiagramsequenceDiagram
participant WS as WebSocket Service
participant Sub as Subscription Manager
WS ->> WS: Connection Closed
alt Resources Exist
WS ->> Sub: Re-establish Subscription
Sub -->> WS: Subscription Restored
end
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🔇 Additional comments (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/js/services/ws.js (1)
96-96
: Consider adding reconnection/backoff logic to avoid potential repeated subscription attempts upon network issues.If the network is momentarily down, this line might trigger repeated subscription attempts. Consider implementing a retry strategy with exponential backoff or verifying the connection is available before re-subscribing.
src/js/services/ws.cy.js (2)
88-90
: Naming consistency suggestion for clarity.
closedTest
andaddTest
clearly represent the test data, but consider naming them in a more descriptive manner (e.g.,closedResource
/additionalResource
) to align better with domain concepts.
121-124
: Clarify or comment on the intended workflow around repeated socket closures.Closing the socket again immediately after an add request may simulate frequent or abnormal disconnections. A short comment explaining this scenario would aid future readers.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/js/services/ws.cy.js
(2 hunks)src/js/services/ws.js
(1 hunks)
🔇 Additional comments (5)
src/js/services/ws.cy.js (5)
10-16
: Good addition of a dedicated spy for verifying the 'start' event behavior.Using
.once('start', resolve)
ensures the promise resolves only once on the first start event, preventing test flakiness if the service triggers multiple 'start' events.
91-100
: Verify data shape consistency within the notification.The
notification.data.data
object is deeply nested. If many layers are planned, confirm that the service's message handler can handle nested data structures. Otherwise, consider flattening to improve readability and reduce potential confusion.
107-107
: Check whether repeated subscription calls might cause duplicate side effects.Calling
subscribe
in theclose
event can re-trigger the subscription logic if the socket is repeatedly closed and reopened in quick succession. Confirm that this behavior is desired and doesn't generate extra messages on the server side.
115-120
: Use additional assertions to ensure the correct argument shape during repeated calls.Confirm that the second call's arguments not only match
notification
but also meet any internal invariants (e.g., validresources
, presence of required fields, etc.).
126-133
: Excellent thoroughness in verifying repeated calls.This sequence comprehensively tests the scenario of adding more resources and closing the socket again. It helps ensure that the service consistently re-issues the correct subscription requests.
RoundingWell Care Ops Frontend Run #7126
Run Properties:
|
Project |
RoundingWell Care Ops Frontend
|
Branch Review |
websocket-close
|
Run status |
Passed #7126
|
Run duration | 02m 54s |
Commit |
116503f2c2: Remove destructuring merge
|
Committer | Paul Falgout |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
1
|
Pending |
0
|
Skipped |
0
|
Passing |
313
|
View all changes introduced in this branch ↗︎ |
At least in tests sometimes `_files` isn’t iterable causing the test to fail.
18779c9
to
116503f
Compare
Pull Request Test Coverage Report for Build 38103d80-46ab-4f5e-8949-6af18b02836eDetails
💛 - Coveralls |
Shortcut Story ID: [sc-58128]
This doesn't really account for lost connection.. ie: it won't retry until the connection is restored. but that's probably a pretty edgy-case where the connection is lost.. and regained without the user changing the context at any point
Summary by CodeRabbit
Bug Fixes
Tests
New Features