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

Prevent zombie presence events #208

Merged
merged 6 commits into from
Jun 18, 2024
Merged

Prevent zombie presence events #208

merged 6 commits into from
Jun 18, 2024

Conversation

7hong13
Copy link
Contributor

@7hong13 7hong13 commented Jun 17, 2024

What this PR does / why we need it?

Presence events are managed using the presenceEventQueue in the Yorkie Android SDK. When _presences collects a new value, it iterates through the presenceEventQueue, filters for related presence events, and emits them into the eventStream. However, because _presences is a StateFlow, when new values are emitted to _presences rapidly, only the most recent value is collected, and only its accompanying presence event is emitted into the eventStream. This can leave other unprocessed presence events as zombies in the presenceEventQueue, causing unintended behaviors.
This PR addresses the issue by ensuring all presence events are either properly emitted or dropped.

Any background context you want to provide?

What are the relevant tickets?

Fixes #

Checklist

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

Summary by CodeRabbit

  • New Features

    • Introduced a new test to ensure presence event queues are empty after consecutive presence changes.
  • Chores

    • Updated CI workflow to move CODECOV_TOKEN configuration to improve environment management.

@7hong13 7hong13 added the bug 🐞 Something isn't working label Jun 17, 2024
@7hong13 7hong13 requested a review from skhugh June 17, 2024 04:37
@7hong13 7hong13 self-assigned this Jun 17, 2024
@7hong13 7hong13 added this to the 0.4.25 milestone Jun 17, 2024
Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

This update includes several changes to the CI workflow and test functions within the Yorkie project. The main update relocates the CODECOV_TOKEN configuration within the CI workflow file. Additional test functions are added, and references are simplified for better readability. Internal properties in the Document.kt file have also been adjusted to accommodate new testing-related logic.

Changes

Files Change Summaries
.github/workflows/ci.yml Moved CODECOV_TOKEN from the with block to the env block under codecov/codecov-action@v4 step in jobs.
yorkie/src/androidTest/kotlin/.../PresenceTest.kt Added new test test_whether_presence_event_queue_is_empty_after_consecutive_presence_changes.
yorkie/src/androidTest/kotlin/.../JsonTreeSplitMergeTest.kt Replaced JsonTreeTest.updateAndSync with updateAndSync in multiple test functions for simplification.
yorkie/src/main/kotlin/.../Document.kt Changed presenceEventQueue visibility to internal and added a new variable clearPresenceEventQueue. Adjusted logic for clearing the queue.

Poem

In the code, a token moves,
Enhancing flow with graceful grooves.
Tests align, they sing anew,
Presence checked, events subdue.
🌟 Clear queues and changes blend,
Yorkie thrives, improvements send. 🐇✨


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

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.

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 1367862 and 930f076.

Files selected for processing (4)
  • .github/workflows/ci.yml (1 hunks)
  • yorkie/src/androidTest/kotlin/dev/yorkie/core/PresenceTest.kt (1 hunks)
  • yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeSplitMergeTest.kt (16 hunks)
  • yorkie/src/main/kotlin/dev/yorkie/document/Document.kt (4 hunks)
Additional comments not posted (5)
.github/workflows/ci.yml (1)

122-123: Moving CODECOV_TOKEN from with to env is a good practice as it enhances the clarity and maintainability of the environment variables.

yorkie/src/androidTest/kotlin/dev/yorkie/document/json/JsonTreeSplitMergeTest.kt (1)

8-8: Using a direct import for updateAndSync improves readability by reducing verbosity, aligning with the DRY principle.

yorkie/src/main/kotlin/dev/yorkie/document/Document.kt (2)

103-104: Marking presenceEventQueue as @VisibleForTesting and changing its visibility to internal is a prudent change for encapsulation and allows for better unit testing.


Line range hint 364-382: The logic to clear the presenceEventQueue based on certain conditions helps prevent zombie presence events. Ensure comprehensive tests cover these new conditions to avoid potential edge cases.

Verification successful

The search results indicate that there are references to presenceEventQueue in the PresenceTest.kt file located in the yorkie/src/androidTest/kotlin/dev/yorkie/core/ directory. This suggests that there are tests related to the presenceEventQueue.

  • yorkie/src/androidTest/kotlin/dev/yorkie/core/PresenceTest.kt: assertTrue(d1.presenceEventQueue.isEmpty())
  • yorkie/src/androidTest/kotlin/dev/yorkie/core/PresenceTest.kt: assertTrue(d2.presenceEventQueue.isEmpty())

These references imply that the presenceEventQueue is being tested to ensure it is empty under certain conditions. This aligns with the need to verify the clearing logic of the presenceEventQueue.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the comprehensive coverage of tests related to presence event queue clearing.

# Test: Search for tests related to presence event queue. Expect: Tests covering new conditions.
rg --type kotlin $'presenceEventQueue' yorkie/src/androidTest/kotlin/dev/yorkie/document/

Length of output: 88



Script:

#!/bin/bash
# Description: Verify the presence of comprehensive tests related to presence event queue clearing.

# Step 1: List all Kotlin test files in the repository
echo "Listing all Kotlin test files in the repository..."
fd --type f --extension kt --search-path yorkie/src/test/ > kotlin_test_files.txt
fd --type f --extension kt --search-path yorkie/src/androidTest/ >> kotlin_test_files.txt

# Step 2: Search for references to presenceEventQueue in all Kotlin test files
echo "Searching for references to presenceEventQueue in Kotlin test files..."
rg --type kotlin 'presenceEventQueue' $(cat kotlin_test_files.txt)

Length of output: 3303

yorkie/src/androidTest/kotlin/dev/yorkie/core/PresenceTest.kt (1)

830-874: The test function test_whether_presence_event_queue_is_empty_after_consecutive_presence_changes effectively validates the clearing of the presence event queue after multiple presence updates. This is crucial for ensuring that zombie presence events do not persist in the system.

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 930f076 and 15c438a.

Files selected for processing (1)
  • yorkie/src/androidTest/kotlin/dev/yorkie/core/PresenceTest.kt (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • yorkie/src/androidTest/kotlin/dev/yorkie/core/PresenceTest.kt

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 15c438a and 59af135.

Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

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 59af135 and 8d96530.

Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

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 8d96530 and 49393e9.

Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

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 49393e9 and 7ac99c5.

Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

@7hong13 7hong13 merged commit 60ea15d into main Jun 18, 2024
4 of 6 checks passed
@7hong13 7hong13 deleted the fix_presence_event branch June 18, 2024 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants