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

Return ErrClientNotActivated for deactivated clients on WatchDocument #877

Merged
merged 1 commit into from
May 28, 2024

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented May 28, 2024

What this PR does / why we need it:

Return ErrClientNotActivated for deactivated clients

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced the ability to watch events on a document.
    • Added functionality to deactivate a client for testing purposes.
  • Enhancements

    • Ensured that only activated clients can access client information.
    • Improved error handling for deactivated clients during stream operations.
  • Bug Fixes

    • Corrected function calls to ensure client activation checks are performed.
  • Testing

    • Added tests for stream behavior involving deactivated clients.

Copy link

coderabbitai bot commented May 28, 2024

Walkthrough

The changes introduce a new Watch function in the Client struct for monitoring document events and modify existing functions to utilize this new method. Additionally, client activation checks are enhanced by adding an EnsureActivated method, renaming FindClientInfo to FindActiveClientInfo, and updating server logic to reflect these changes. Integration tests are also updated to verify the behavior of deactivated clients.

Changes

File Change Summary
client/client.go Added Watch function to Client struct and updated runWatchLoop to use this new method.
server/backend/database/client_info.go Introduced EnsureActivated method to ClientInfo struct.
server/clients/clients.go Renamed FindClientInfo to FindActiveClientInfo and added activation check logic.
server/rpc/yorkie_server.go Replaced calls to FindClientInfo with FindActiveClientInfo in various yorkieServer methods.
server/server.go Added DeactivateClient function in Yorkie struct and necessary imports for context and clients.
test/integration/client_test.go Added import for connectrpc.com/connect and introduced a test for deactivated client's stream behavior.

🐇
In code, we watch the docs so dear,
Ensuring clients are active and clear.
With tests to guard the streams so bright,
Our Yorkie server's future is light.
Amidst the bytes and lines so neat,
The rabbit's code is quite a feat!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 full the 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@hackerwins hackerwins marked this pull request as ready for review May 28, 2024 09:15
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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2d71055 and 975a9ac.
Files selected for processing (6)
  • client/client.go (2 hunks)
  • server/backend/database/client_info.go (1 hunks)
  • server/clients/clients.go (1 hunks)
  • server/rpc/yorkie_server.go (6 hunks)
  • server/server.go (2 hunks)
  • test/integration/client_test.go (2 hunks)
Additional comments not posted (7)
server/clients/clients.go (1)

91-106: The changes to FindActiveClientInfo correctly implement the check for client activation. Consider adding a comment explaining why this check is necessary, as it represents a behavior change from the previous FindClientInfo.

server/server.go (1)

137-149: The DeactivateClient function is introduced for testing purposes. Please verify the use of an empty string for the API key in GetProjectFromAPIKey. If this is a placeholder, consider replacing it with a meaningful value or add a comment explaining its usage.

server/backend/database/client_info.go (1)

196-203: The EnsureActivated method correctly implements the activation check. This is a crucial part of handling deactivated clients as per the PR's objectives.

test/integration/client_test.go (1)

177-208: The new test for the behavior of a deactivated client's stream is well-implemented. It correctly checks for the expected error code when a deactivated client attempts to watch a document.

server/rpc/yorkie_server.go (1)

147-147: The replacement of FindClientInfo with FindActiveClientInfo in various methods is correctly implemented. This ensures that only activated clients can interact with the system, aligning with the PR's objectives.

Also applies to: 220-220, 324-324, 398-398, 517-517, 630-630

client/client.go (2)

447-465: The implementation of the Watch function appears correct and adheres to the described functionality of watching document events. Good use of error handling for unattached documents.


481-481: Refactoring to use the new Watch method in runWatchLoop simplifies the code and improves maintainability. Well done on encapsulating the watch document logic.

Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 14.70588% with 29 lines in your changes are missing coverage. Please review.

Project coverage is 50.52%. Comparing base (2d71055) to head (975a9ac).

Files Patch % Lines
client/client.go 0.00% 13 Missing ⚠️
server/server.go 0.00% 10 Missing ⚠️
server/backend/database/client_info.go 0.00% 5 Missing ⚠️
server/rpc/yorkie_server.go 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #877      +/-   ##
==========================================
- Coverage   50.56%   50.52%   -0.05%     
==========================================
  Files          70       70              
  Lines       10398    10419      +21     
==========================================
+ Hits         5258     5264       +6     
- Misses       4608     4625      +17     
+ Partials      532      530       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hackerwins hackerwins changed the title Return ErrClientNotActivated for deactivated clients Return ErrClientNotActivated for deactivated clients on WatchDocument May 28, 2024
@hackerwins hackerwins merged commit 6367d90 into main May 28, 2024
4 checks passed
@hackerwins hackerwins deleted the deactivated-client-stream branch May 28, 2024 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant