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

[ECO-5123] Fix crash when running integration tests #146

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Nov 25, 2024

Note: This is based on top of #131; please review that one first.

This fixes an intermittent crash (Non-initial ATTACHED state change with resumed == false should have a reason) in the integration tests which happened because the manager sometimes processed the initial ATTACHED contributor state change after the attach() call completed. I’ve followed my first suggestion in ably/specification#239 for how to address this.

Resolves #121.

Summary by CodeRabbit

  • New Features

    • Enhanced concurrency model with async functionality for room lifecycle management methods.
    • Improved state management and error handling for room lifecycle operations.
  • Bug Fixes

    • Refined handling of state changes and error conditions in lifecycle manager operations.
  • Tests

    • Updated and new test cases added to ensure comprehensive coverage of room lifecycle behaviors and error handling.

This fixes an intermittent crash ("Non-initial ATTACHED state change
with resumed == false should have a reason") in the integration tests
which happened because the manager sometimes processed the initial
ATTACHED contributor state change after the `attach()` call completed.
I’ve followed my first suggestion in [1] for how to address this.

Resolves #121.

[1] ably/specification#239
Copy link

coderabbitai bot commented Nov 25, 2024

Walkthrough

This pull request introduces significant modifications to the RoomLifecycleManager and its associated protocols in RoomLifecycleManager.swift, primarily by adding async functionality to various methods and properties. The DefaultRoomLifecycleManager class sees refined state change handling and improved error management. Additionally, the test suite for DefaultRoomLifecycleManager is updated with new and modified test cases to align with these changes, enhancing the robustness of the lifecycle management logic and ensuring proper behavior under various conditions.

Changes

File Change Summary
Sources/AblyChat/RoomLifecycleManager.swift Added async functionality to methods and properties in RoomLifecycleContributorChannel and RoomLifecycleManager. Updated state change handling in DefaultRoomLifecycleManager. Enhanced error handling and logging.
Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift Updated existing test cases and added new ones to reflect changes in lifecycle operations, error handling, and state management.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • umair-ably
  • maratal

🐰 "In the room where changes bloom,
Async methods chase away the gloom.
State and errors now align,
Lifecycle flows, oh how they shine!
With tests robust, we hop with glee,
In our code, all's well, you see!" 🐇


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

🧹 Outside diff range and nitpick comments (3)
Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift (3)

1425-1447: Address the TODO comment for specification alignment

There's a TODO comment at line 1425 indicating that the criteria for deciding whether an ATTACHED state change represents a discontinuity should be updated once aligned with the specification (see ably/specification#239). To maintain code clarity and ensure consistency with the latest specifications, consider resolving this TODO or tracking it appropriately.

Would you like assistance in implementing the required changes or opening a GitHub issue to track this task?


Line range hint 1425-1480: Consider simplifying test method names for better readability

The test method names are quite lengthy, which might make them harder to read and maintain. For example:

func contributorAttachEvent_withResumeFalse_withOperationInProgress_withContributorAttachedPreviously_recordsPendingDiscontinuityEvent() async throws

Consider using a more concise naming convention that still conveys the purpose of the test. Shorter names can improve code readability and maintainability.


Line range hint 1478-1491: Reminder to address the TODO comment regarding specification updates

At line 1478, there's a TODO comment about changing criteria back once aligned with the specification (see ably/specification#239). To ensure the test reflects the intended behavior per the updated specification, please consider addressing this TODO or creating a task to track it.

Would you like assistance in handling this TODO or opening a GitHub issue to ensure this gets addressed?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3d63cec and 8b5aa47.

📒 Files selected for processing (2)
  • Sources/AblyChat/RoomLifecycleManager.swift (4 hunks)
  • Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift (2 hunks)
🧰 Additional context used
📓 Learnings (2)
Sources/AblyChat/RoomLifecycleManager.swift (2)
Learnt from: lawrence-forooghian
PR: ably-labs/ably-chat-swift#54
File: Sources/AblyChat/RoomLifecycleManager.swift:0-0
Timestamp: 2024-11-12T15:07:31.866Z
Learning: In `RoomLifecycleManager`, handling of unexpected contributor states after attach failure will be addressed in issue #49.
Learnt from: lawrence-forooghian
PR: ably-labs/ably-chat-swift#67
File: Sources/AblyChat/RoomLifecycleManager.swift:225-230
Timestamp: 2024-11-12T15:07:31.865Z
Learning: In the `ably-chat-swift` project, `swift-async-algorithms` provides the `async` property on collections, allowing for asynchronous operations like `contributors.async`.
Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift (2)
Learnt from: lawrence-forooghian
PR: ably-labs/ably-chat-swift#54
File: Tests/AblyChatTests/RoomLifecycleManagerTests.swift:627-631
Timestamp: 2024-11-12T15:07:39.465Z
Learning: The closure `detachImpl` in `RoomLifecycleManagerTests.swift` functions as intended without external state variables to track invocation count.
Learnt from: lawrence-forooghian
PR: ably-labs/ably-chat-swift#54
File: Tests/AblyChatTests/RoomLifecycleManagerTests.swift:335-335
Timestamp: 2024-11-12T15:07:31.865Z
Learning: In Swift Testing, test method names do not need to start with `test`.
🔇 Additional comments (3)
Sources/AblyChat/RoomLifecycleManager.swift (3)

268-268: Initialization of hasBeenAttached property

The new hasBeenAttached property in ContributorAnnotation is properly initialized and integrated into the state tracking, ensuring accurate monitoring of contributor attachment states.


388-388: Addition of test utility function enhances testability

The testsOnly_subscribeToHandledContributorStateChanges() function provides a valuable tool for testing, following naming conventions and improving the capability to monitor contributor state changes in tests.


461-463: Correctly tracking contributor attachment state

Capturing the previous state with hadAlreadyAttached before updating hasBeenAttached ensures that the logic accurately reflects whether the contributor has been attached before. This is crucial for handling state changes appropriately.

Sources/AblyChat/RoomLifecycleManager.swift Show resolved Hide resolved
Sources/AblyChat/RoomLifecycleManager.swift Show resolved Hide resolved
Base automatically changed from 131-implement-CHA-RL9 to main November 25, 2024 20:12
@lawrence-forooghian lawrence-forooghian merged commit e716eff into main Nov 25, 2024
12 checks passed
@lawrence-forooghian lawrence-forooghian deleted the 121-integration-tests-crash branch November 25, 2024 20:13
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.

Investigate integration tests crash
2 participants