Skip to content
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

Support RTP17g1: presence auto re-enter with a different connId #1913

Merged
merged 4 commits into from
Nov 7, 2024

Conversation

SimonWoolf
Copy link
Member

@SimonWoolf SimonWoolf commented Oct 25, 2024

see ably/specification#215

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced member re-entry logic in real-time presence management.
    • Added a new test case for handling presence re-entry with different connection IDs.
  • Bug Fixes

    • Improved error handling during member re-entry to prevent outdated member IDs.
  • Tests

    • Refactored test cases to utilize async/await for better readability and maintainability.
    • Introduced new test scenarios to validate presence behavior under various conditions.

Copy link

coderabbitai bot commented Oct 25, 2024

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The changes involve modifications to the RealtimePresence class and the SharedHelper class, enhancing their methods for better error handling and asynchronous operation. The _ensureMyMembersPresent method was updated to conditionally handle member IDs based on connection status, while the becomeSuspended and _becomeSuspended methods were adjusted to return promises, improving their usability in asynchronous contexts. Additionally, the test suite for presence functionality was refactored to utilize async/await syntax, improving readability and maintainability.

Changes

File Change Summary
src/common/lib/client/realtimepresence.ts Updated _ensureMyMembersPresent to conditionally suppress id based on connectionId. Simplified error handling by directly calling _enterOrUpdateClient.
test/common/modules/shared_helper.js Modified becomeSuspended to return the result of _becomeSuspended. Updated _becomeSuspended to return a promise when no callback is provided.
test/realtime/presence.test.js Refactored tests to use async/await, added new test case for presence re-entering with different connection IDs, and improved overall test structure for clarity.

Poem

🐇 In the realm of code where bunnies play,
Changes hop in a bright new way.
With promises dancing, errors take flight,
Async awaits bring clarity and light.
So let us celebrate, with joy and cheer,
For smoother flows and code that's clear! 🐇✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/1913/bundle-report October 25, 2024 19:46 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1913/typedoc October 25, 2024 19:46 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1913/features October 25, 2024 19:46 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
test/common/modules/shared_helper.js (2)

271-277: LGTM with a suggestion: Consider adding error handling

The changes properly support both callback and promise-based patterns, improving the method's flexibility. However, consider adding error handling for potential connection state transition failures.

Consider wrapping the state transition in a try-catch block:

 if (cb) {
+  try {
     realtime.connection.once('suspended', function () {
       cb();
     });
+  } catch (err) {
+    cb(err);
+  }
 } else {
+  try {
     return realtime.connection.once('suspended');
+  } catch (err) {
+    return Promise.reject(err);
+  }
 }

Line range hint 260-277: Consider documenting the test helper's role in presence testing

These changes enhance the test helper's capability to simulate connection state transitions, which is crucial for testing presence auto re-entry scenarios. Consider adding documentation that explains how this helper should be used in presence-related tests, particularly for scenarios involving connection ID changes.

Add a JSDoc comment to explain the helper's role:

/**
 * Simulates a connection becoming suspended, which is useful for testing presence
 * re-entry scenarios, especially with different connection IDs.
 * @param {Realtime} realtime - The realtime client instance
 * @param {Function} [cb] - Optional callback, if not provided returns a promise
 * @returns {Promise<void>} - Returns a promise when no callback is provided
 */
test/realtime/presence.test.js (3)

1714-1714: Unnecessary Transport Parameter remainPresentFor

The remainPresentFor: 5000 parameter in helper.AblyRealtime({transportParams: {remainPresentFor: 5000}}); may not be necessary for this test or could affect other tests if not reset.

Consider removing the parameter or adding a comment explaining its necessity.


1721-1721: Handle Potential Errors When Awaiting Promises

When calling await channel.presence.get(), it's good practice to handle potential errors to prevent unhandled promise rejections.

Consider wrapping the call in a try-catch block:

- await channel.presence.get()
+ try {
+   await channel.presence.get();
+ } catch (err) {
+   // Handle error appropriately
+ }

1741-1741: Clarify Assertion Message for Message ID Comparison

The assertion assert.notEqual(enter.id, member1.id, 'Check the new enter did not have the msgId of the original'); checks that the message IDs differ. Ensure that the reasoning behind this expectation is documented for future maintainability.

Consider enhancing the assertion message or adding comments to explain why the message IDs should not be equal after reconnection.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0bd7aa5 and 26c1d86.

📒 Files selected for processing (3)
  • src/common/lib/client/realtimepresence.ts (2 hunks)
  • test/common/modules/shared_helper.js (2 hunks)
  • test/realtime/presence.test.js (2 hunks)
🔇 Additional comments (4)
test/common/modules/shared_helper.js (1)

260-260: LGTM: Improved promise support

The change enhances the method by properly propagating the promise from _becomeSuspended, making it more compatible with async/await patterns while maintaining backward compatibility with callbacks.

src/common/lib/client/realtimepresence.ts (1)

441-442: LGTM: Clean implementation of RTP17g1 spec

The implementation correctly suppresses the member ID when the connection ID has changed, preventing stale member IDs from being used during presence re-entry.

test/realtime/presence.test.js (2)

1667-1674: Possible Logic Issue in Presence Synchronization Check

The condition if (channel.presence.syncComplete) checks if the presence synchronization is complete before calling channel.sync(). This seems counterintuitive since you might want to synchronize only if it's not complete.

Please verify whether the condition should be negated to ensure synchronization happens when it is incomplete:

- if (channel.presence.syncComplete) {
+ if (!channel.presence.syncComplete) {

1730-1737: Assumption About Connection ID Change May Not Always Hold

The test assumes that after reconnection, the connection ID will change due to suspension. However, if the suspension duration is short, the connection may resume with the same ID.

Please verify whether the test reliably reproduces the scenario where the connection ID changes. If not, consider simulating a longer suspension or adjusting the test to account for both possibilities.

src/common/lib/client/realtimepresence.ts Outdated Show resolved Hide resolved
test/realtime/presence.test.js Show resolved Hide resolved
test/realtime/presence.test.js Show resolved Hide resolved
@SimonWoolf
Copy link
Member Author

@coderabbitai pause

Copy link

coderabbitai bot commented Oct 30, 2024

✅ Actions performed

Reviews paused.

Copy link
Collaborator

@ttypic ttypic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests lgtm, one minor comment:

src/common/lib/client/realtimepresence.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/1913/features November 7, 2024 19:10 Inactive
@SimonWoolf SimonWoolf force-pushed the auto-re-enter-diff-connid branch from cf94386 to acf45a0 Compare November 7, 2024 19:14
@github-actions github-actions bot temporarily deployed to staging/pull/1913/typedoc November 7, 2024 19:15 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1913/bundle-report November 7, 2024 19:15 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1913/features November 7, 2024 19:15 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants