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

Introduce a wait to work around history not being “live” #176

Closed
wants to merge 1 commit into from

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Dec 4, 2024

(The integration tests are still failing, though, due to #169, but at least they’re now failing in a consistent manner.)

Resolves #167.

Summary by CodeRabbit

  • Bug Fixes

    • Improved message retrieval mechanism to prevent empty message arrays by implementing a retry loop.
    • Enhanced robustness of the integration tests for message fetching.
  • Documentation

    • Updated comments to clarify the rationale behind the changes and reference related discussions.

(The integration tests are still failing, though, due to #169, but at
least they’re now failing in a consistent manner.)

Resolves #167.
Copy link

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes in this pull request focus on modifying the basicIntegrationTest function within the IntegrationTests struct in IntegrationTests.swift. A new retry mechanism for fetching previous messages has been implemented to address instances where the messages.items array may return empty. This mechanism includes a loop that attempts to retrieve messages until a non-empty result is achieved, with a one-second delay between attempts. Comments have been updated to clarify the reasoning behind this adjustment.

Changes

File Path Change Summary
Tests/AblyChatTests/IntegrationTests.swift Modified basicIntegrationTest to implement a retry loop for fetching messages, replacing the original message retrieval line. Updated comments to explain the changes.

Assessment against linked issues

Objective Addressed Explanation
Fix the failing pre-subscription history integration test (#[167])

Poem

🐇 In the land of code where messages hide,
A rabbit found a way to turn the tide.
With retries and waits, the messages flow,
No more empty arrays, just watch them grow!
Hopping through tests, with joy we cheer,
For every fetched message, the goal is 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.

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)
Tests/AblyChatTests/IntegrationTests.swift (1)

120-138: Consider adding timeout information to the documentation

The comment effectively explains the issue and workaround. However, since this is a retry mechanism, it would be helpful to document:

  1. Whether there should be a maximum number of retries
  2. What timeout scenarios should be considered
  3. What behavior is expected if history remains consistently empty
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5676cac and 1cb8801.

📒 Files selected for processing (1)
  • Tests/AblyChatTests/IntegrationTests.swift (1 hunks)
🔇 Additional comments (1)
Tests/AblyChatTests/IntegrationTests.swift (1)

139-148: Consider adding timeout and exponential backoff

While the current implementation works around the history system limitation, it could be more robust with:

  1. A maximum retry limit or timeout to prevent infinite loops
  2. Exponential backoff instead of fixed delay
  3. Error handling for timeout scenarios

Here's a suggested implementation:

        let rxMessagesBeforeSubscribing = try await {
+           let maxAttempts = 5
+           var attempt = 0
            while true {
+               attempt += 1
                let messages = try await rxMessageSubscription.getPreviousMessages(params: .init())
                if !messages.items.isEmpty {
                    return messages
                }
+               guard attempt < maxAttempts else {
+                   throw NSError(domain: "IntegrationTests",
+                               code: 1,
+                               userInfo: [NSLocalizedDescriptionKey: "Timeout waiting for history"])
+               }
-               try await Task.sleep(nanoseconds: NSEC_PER_SEC)
+               // Exponential backoff: 1s, 2s, 4s, 8s, 16s
+               try await Task.sleep(nanoseconds: UInt64(pow(2.0, Double(attempt - 1))) * NSEC_PER_SEC)
            }
        }()

Let's verify if similar retry patterns exist elsewhere in the codebase:

@lawrence-forooghian
Copy link
Collaborator Author

Replaced by #177.

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.

Pre-subscription history integration test is failing
2 participants