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

LiveObjects SYNC sequence tests #1894

Merged
merged 10 commits into from
Nov 8, 2024

Conversation

VeskeR
Copy link
Contributor

@VeskeR VeskeR commented Oct 16, 2024

This PR is based on #1891, please review it first.

Adds LiveObjects integration tests for functionality introduced in #1887, #1890 and #1891.

NOTE: next Live Objects tests are expected to fail until https://ably.atlassian.net/browse/DTP-982 is fixed:

  • builds state object tree from STATE_SYNC sequence on channel attachment
  • LiveMap is initialized with initial value from STATE_SYNC sequence
  • LiveMaps can reference the same object in their keys

Failure is due to missing state object in STATE_SYNC sequence for a map which has zero values.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a size() method to the LiveMap class for retrieving the size of the data map.
    • Added a new live_objects_helper dependency for testing.
    • Implemented a LiveObjectsHelper class to manage LiveObjects state on channels.
    • Added a feature flag enableChannelState for new app creation.
    • Enhanced the test suite with a new helper function for channel options related to LiveObjects.
  • Bug Fixes

    • Improved error handling in the test suite for scenarios when the LiveObjects plugin is absent.
  • Documentation

    • Updated test suite structure for improved clarity and maintainability.

@github-actions github-actions bot temporarily deployed to staging/pull/1894/features October 16, 2024 08:23 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/bundle-report October 16, 2024 08:23 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/typedoc October 16, 2024 08:23 Inactive
@VeskeR VeskeR force-pushed the DTP-951/implement-get-root branch from ccb1a06 to 0cdc7c7 Compare October 16, 2024 09:34
@VeskeR VeskeR force-pushed the liveobjects/sync-sequence-tests branch from 6a56b3e to 3fc1df0 Compare October 16, 2024 09:34
@github-actions github-actions bot temporarily deployed to staging/pull/1894/features October 16, 2024 09:35 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/bundle-report October 16, 2024 09:35 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/typedoc October 16, 2024 09:35 Inactive
@VeskeR VeskeR force-pushed the liveobjects/sync-sequence-tests branch from 3fc1df0 to 3ee12cd Compare October 17, 2024 08:05
@github-actions github-actions bot temporarily deployed to staging/pull/1894/bundle-report October 17, 2024 08:05 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/typedoc October 17, 2024 08:05 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/features October 17, 2024 08:05 Inactive
@VeskeR VeskeR changed the title [WIP] Liveobjects SYNC sequence tests Liveobjects SYNC sequence tests Oct 17, 2024
@VeskeR VeskeR marked this pull request as ready for review October 17, 2024 08:06
Copy link

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes in this pull request introduce several new functionalities and modifications across multiple files. A new size() method is added to the LiveMap class, which returns the size of the internal Map object. A new helper class, LiveObjectsHelper, is created to manage LiveObjects state, along with its associated methods. Additionally, a feature flag is added to the createNewApp function in the testapp_manager.js file, and the test suite is updated to incorporate these changes, including renaming functions and adding new test cases.

Changes

File Path Change Summary
src/plugins/liveobjects/livemap.ts - Method added: size(): number in class LiveMap
test/common/globals/named_dependencies.js - New module added: live_objects_helper with paths for browser and Node.js
test/common/modules/live_objects_helper.js - Class added: LiveObjectsHelper
- Methods added: initForChannel, _createAndSetOnMap, _mapCreateOp, _mapSetOp, _counterCreateOp, _stateRequest
- Exported singleton instance of LiveObjectsHelper
test/common/modules/testapp_manager.js - Added feature flag enableChannelState in createNewApp function
test/realtime/live_objects.test.js - Function renamed: LiveObjectsRealtimeRealtimeWithLiveObjects
- Function added: channelOptionsWithLiveObjects
- Expanded test cases and improved organization of tests

Possibly related PRs

Suggested reviewers

  • ttypic
  • mschristensen
  • owenpearson

🐰 In the garden, hopping free,
A new method blooms for all to see.
With helpers and flags, our code's a delight,
Testing the changes, we’ll code through the night!
So let’s celebrate with joy and cheer,
For every new feature that brings us near! 🌼


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.

@VeskeR VeskeR changed the title Liveobjects SYNC sequence tests LiveObjects SYNC sequence tests Oct 17, 2024
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: 5

🧹 Outside diff range and nitpick comments (4)
src/plugins/liveobjects/livemap.ts (1)

63-65: LGTM! Consider adding readonly modifier.

The implementation of the size() method looks good. It correctly returns the size of the internal Map object, which is consistent with the class structure and provides a useful accessor for the map's size.

As a minor enhancement, consider adding the readonly modifier to the method signature:

readonly size(): number {
  return this._dataRef.data.size;
}

This would explicitly indicate that the method doesn't modify the object's state, which can be helpful for TypeScript users and potentially enable certain optimizations.

test/common/modules/testapp_manager.js (1)

136-136: LGTM! Consider adding a comment for clarity.

The addition of the 'enableChannelState' feature flag to the post_apps object is straightforward and appears to be intentional. This change will affect the configuration of newly created test apps, potentially enabling a new feature or behavior in the test environment.

Consider adding a brief comment explaining the purpose of this feature flag for future maintainers. For example:

// Enable channel state tracking for test apps
testData.post_apps.featureFlags = ['enableChannelState'];

This will help other developers understand the intention behind this configuration.

test/realtime/live_objects.test.js (2)

109-110: Ensure client is properly closed after test completion

At lines 109-110, a client is created but not explicitly closed after the test finishes:

const client = RealtimeWithLiveObjects(helper);

Ensure that the client is properly closed to prevent resource leaks. You can wrap the test logic with helper.monitorConnectionThenCloseAndFinish to manage the client lifecycle, which you've done correctly in other tests.


383-384: Clarify assertion message for nested counter's value

In lines 383-384, the assertion checks the value of a nested counter:

expect(counterFromReferencedMap.value()).to.equal(20, 'Check nested counter has correct value');

Consider enhancing the assertion message to specify which counter is being checked for clarity:

- expect(counterFromReferencedMap.value()).to.equal(20, 'Check nested counter has correct value');
+ expect(counterFromReferencedMap.value()).to.equal(20, 'Check that "counterFromReferencedMap" has the correct value');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0cdc7c7 and 3ee12cd.

📒 Files selected for processing (5)
  • src/plugins/liveobjects/livemap.ts (1 hunks)
  • test/common/globals/named_dependencies.js (1 hunks)
  • test/common/modules/live_objects_helper.js (1 hunks)
  • test/common/modules/testapp_manager.js (1 hunks)
  • test/realtime/live_objects.test.js (3 hunks)
🧰 Additional context used
🪛 Biome
test/common/modules/live_objects_helper.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)


[error] 171-171: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

🔇 Additional comments (2)
test/common/globals/named_dependencies.js (1)

29-32: LGTM! New dependency added correctly.

The new live_objects_helper entry has been added consistently with the existing pattern. Both browser and Node.js paths are provided, which is in line with the structure of other entries in this file.

To ensure the correctness of the paths and the existence of the referenced module, please run the following verification script:

✅ Verification successful

Verification Successful: live_objects_helper module exists and paths are correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the live_objects_helper module

# Test: Check if the file exists at the specified path
if [ -f "test/common/modules/live_objects_helper.js" ]; then
    echo "live_objects_helper.js file found at the specified path."
else
    echo "Error: live_objects_helper.js file not found at the specified path."
    exit 1
fi

# Test: Search for any imports or requires of the new module
echo "Searching for usage of live_objects_helper in the codebase:"
rg --type js "require\(['\"]test/common/modules/live_objects_helper['\"]" || echo "No usage found. This might be expected if the module is not yet used in tests."

Length of output: 554

src/plugins/liveobjects/livemap.ts (1)

63-65: Well-integrated addition to the LiveMap class

The size() method is a valuable addition to the LiveMap class. It's well-placed within the class structure and provides functionality that users would expect from a map-like object. This method enhances the usability of the LiveMap class by allowing easy access to the size of the underlying map, which is a common operation in many use cases.

The addition of this method aligns the LiveMap interface more closely with the standard JavaScript Map interface, which is a positive design choice for API consistency and user expectations.

@VeskeR VeskeR force-pushed the liveobjects/sync-sequence-tests branch from 3ee12cd to a64b155 Compare October 17, 2024 08:42
@github-actions github-actions bot temporarily deployed to staging/pull/1894/features October 17, 2024 08:43 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/bundle-report October 17, 2024 08:43 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/typedoc October 17, 2024 08:43 Inactive
@VeskeR VeskeR force-pushed the liveobjects/sync-sequence-tests branch from a64b155 to 1510c81 Compare October 17, 2024 08:45
@github-actions github-actions bot temporarily deployed to staging/pull/1894/bundle-report October 17, 2024 08:45 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/features October 17, 2024 08:45 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1894/typedoc October 17, 2024 08:45 Inactive
@VeskeR VeskeR force-pushed the DTP-951/implement-get-root branch from d3e15d9 to d637bd7 Compare October 22, 2024 05:27
@VeskeR VeskeR force-pushed the liveobjects/sync-sequence-tests branch from 42c9d5c to 566bf00 Compare October 22, 2024 05:28
Base automatically changed from DTP-951/implement-get-root to integration/liveobjects October 22, 2024 10:18
@VeskeR VeskeR merged commit 81237f3 into integration/liveobjects Nov 8, 2024
8 of 14 checks passed
@VeskeR VeskeR deleted the liveobjects/sync-sequence-tests branch November 8, 2024 05:08
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.

3 participants