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

fix: add missing channel modes for message channel #89

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

ttypic
Copy link
Collaborator

@ttypic ttypic commented Dec 10, 2024

Fix bug then room with all features enabled stops receiving messages

Summary by CodeRabbit

  • New Features

    • Enhanced message handling with new test scenarios for room configurations.
  • Bug Fixes

    • Streamlined logic for constructing channel modes in message options.
  • Tests

    • Updated existing test for message retrieval to clarify room feature context.
    • Added a new test for message functionality with all room features enabled.
    • Improved assertions in tests to verify correct channel modes for shared channels.

@ttypic ttypic requested a review from sacOO7 December 10, 2024 14:00
Copy link

coderabbitai bot commented Dec 10, 2024

Walkthrough

The pull request introduces modifications to the RoomOptions data class in RoomOptions.kt, specifically updating the messagesChannelOptions function to streamline the construction of channel modes using buildList. The validateRoomOptions function remains unchanged. Additionally, in the SandboxTest class, a test method was renamed for clarity, and a new test method was added to cover message functionality with all room features enabled. The RoomFeatureSharedChannelTest class also saw updates to assertions regarding expected channel modes. These changes enhance the readability of the code and the test coverage for message handling.

Changes

File Path Change Summary
chat-android/src/main/java/com/ably/chat/RoomOptions.kt - Modified messagesChannelOptions function to use buildList for constructing channel modes.
- validateRoomOptions function remains unchanged.
chat-android/src/test/java/com/ably/chat/SandboxTest.kt - Renamed test method from should be able to send and retrieve messages to should be able to send and retrieve messages without room features.
- Added new test method should be able to send and retrieve messages with all room features enabled.
chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt - Updated assertions in the test method to expect four channel modes instead of two in capturedChannelOptions.

Possibly related PRs

Suggested reviewers

  • sacOO7

🐰 In the code where options play,
Channel modes now find their way.
Tests expanded, features clear,
Sending messages brings us cheer!
With each change, we hop along,
In this code, we all belong! 🥕


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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/89/dokka December 10, 2024 14:01 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: 0

🧹 Outside diff range and nitpick comments (1)
chat-android/src/test/java/com/ably/chat/SandboxTest.kt (1)

131-149: Consider adding more test scenarios.

While the new test validates the fix for rooms with all features enabled, consider adding tests for:

  1. Message reception when toggling features on/off
  2. Edge cases like rapid feature changes
  3. Concurrent message operations with feature changes

This will ensure the fix is robust across different scenarios.

Would you like me to help draft these additional test cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4d32877 and 2c12aa3.

📒 Files selected for processing (2)
  • chat-android/src/main/java/com/ably/chat/RoomOptions.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/SandboxTest.kt (2 hunks)
🔇 Additional comments (2)
chat-android/src/main/java/com/ably/chat/RoomOptions.kt (1)

124-137: LGTM! Fix ensures message modes are always present.

The refactoring ensures that basic message modes (publish and subscribe) are always added first, followed by conditional presence modes. This fixes the core issue where rooms with all features enabled could stop receiving messages.

Let's verify the channel modes are correctly set:

chat-android/src/test/java/com/ably/chat/SandboxTest.kt (1)

112-112: LGTM! Clear test name improvement.

The renamed test better describes its purpose by explicitly stating it tests messaging without room features.

Copy link
Contributor

@sacOO7 sacOO7 left a comment

Choose a reason for hiding this comment

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

RoomFeatureSharedChannelTest.kt failing at Line 44
It expects 2 modes when presenceOptions are set.
You can update test to check for 4 modes accordingly.

@sacOO7
Copy link
Contributor

sacOO7 commented Dec 10, 2024

This will also include updating checks as per

        Assert.assertEquals(ChannelMode.subscribe, capturedChannelOptions[0].modes[0])
        Assert.assertEquals(ChannelMode.publish, capturedChannelOptions[0].modes[1])
        Assert.assertEquals(ChannelMode.presence, capturedChannelOptions[0].modes[2])
        Assert.assertEquals(ChannelMode.presence_subscribe, capturedChannelOptions[0].modes[3])

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2c12aa3 and cabed6a.

📒 Files selected for processing (3)
  • chat-android/src/main/java/com/ably/chat/RoomOptions.kt (1 hunks)
  • chat-android/src/test/java/com/ably/chat/SandboxTest.kt (2 hunks)
  • chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • chat-android/src/main/java/com/ably/chat/RoomOptions.kt
  • chat-android/src/test/java/com/ably/chat/SandboxTest.kt
🧰 Additional context used
📓 Learnings (1)
chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt (1)
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#75
File: chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt:43-45
Timestamp: 2024-12-02T12:10:18.954Z
Learning: In the `RoomFeatureSharedChannelTest.kt` tests, prefer using assertions like `Assert.assertEquals` that provide detailed error messages over general assertions like `Assert.assertTrue`, to aid in debugging when a test fails due to a missing mode.

Comment on lines +44 to +48
Assert.assertEquals(4, capturedChannelOptions[0].modes.size)
Assert.assertEquals(ChannelMode.publish, capturedChannelOptions[0].modes[0])
Assert.assertEquals(ChannelMode.subscribe, capturedChannelOptions[0].modes[1])
Assert.assertEquals(ChannelMode.presence, capturedChannelOptions[0].modes[2])
Assert.assertEquals(ChannelMode.presence_subscribe, capturedChannelOptions[0].modes[3])
Copy link

@coderabbitai coderabbitai bot Dec 10, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the order of channel modes to match requirements

The order of channel modes needs to be adjusted according to the specified requirements. The current implementation has publish first and subscribe second, but the requirements state that subscribe should be first, followed by publish.

Apply this diff to fix the order:

 Assert.assertEquals(4, capturedChannelOptions[0].modes.size)
-Assert.assertEquals(ChannelMode.publish, capturedChannelOptions[0].modes[0])
-Assert.assertEquals(ChannelMode.subscribe, capturedChannelOptions[0].modes[1])
+Assert.assertEquals(ChannelMode.subscribe, capturedChannelOptions[0].modes[0])
+Assert.assertEquals(ChannelMode.publish, capturedChannelOptions[0].modes[1])
 Assert.assertEquals(ChannelMode.presence, capturedChannelOptions[0].modes[2])
 Assert.assertEquals(ChannelMode.presence_subscribe, capturedChannelOptions[0].modes[3])

Good use of Assert.assertEquals for detailed error messages when tests fail. This follows the recommended practice for better debugging.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Assert.assertEquals(4, capturedChannelOptions[0].modes.size)
Assert.assertEquals(ChannelMode.publish, capturedChannelOptions[0].modes[0])
Assert.assertEquals(ChannelMode.subscribe, capturedChannelOptions[0].modes[1])
Assert.assertEquals(ChannelMode.presence, capturedChannelOptions[0].modes[2])
Assert.assertEquals(ChannelMode.presence_subscribe, capturedChannelOptions[0].modes[3])
Assert.assertEquals(4, capturedChannelOptions[0].modes.size)
Assert.assertEquals(ChannelMode.subscribe, capturedChannelOptions[0].modes[0])
Assert.assertEquals(ChannelMode.publish, capturedChannelOptions[0].modes[1])
Assert.assertEquals(ChannelMode.presence, capturedChannelOptions[0].modes[2])
Assert.assertEquals(ChannelMode.presence_subscribe, capturedChannelOptions[0].modes[3])

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai order for first two modes doesn't matter

Copy link

Choose a reason for hiding this comment

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

@sacOO7, thanks for the clarification. I understand that the order of the first two channel modes (ChannelMode.publish and ChannelMode.subscribe) does not matter. I'll note this for future reviews.


✏️ Learnings added
Learnt from: sacOO7
PR: ably/ably-chat-kotlin#89
File: chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt:44-48
Timestamp: 2024-12-10T14:47:31.404Z
Learning: In tests in `RoomFeatureSharedChannelTest.kt` for the Ably Chat Kotlin project, the order of `ChannelMode.publish` and `ChannelMode.subscribe` in the `modes` array does not affect functionality; assertions should not enforce a specific order for these modes.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link

Code Coverage

File Coverage [94.87%]
chat-android/src/main/java/com/ably/chat/RoomOptions.kt 94.87%
Total Project Coverage 84.85%

Copy link
Contributor

@sacOO7 sacOO7 left a comment

Choose a reason for hiding this comment

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

LGTM

@ttypic ttypic merged commit b6d989c into main Dec 10, 2024
4 checks passed
@ttypic ttypic deleted the fix-channel-creation branch December 10, 2024 14:48
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.

2 participants