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

🌿 use core/asyncutil instead lambdalisue/async #419

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Conversation

Milly
Copy link
Contributor

@Milly Milly commented Sep 15, 2024

This allows we to test promise states more accurately.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of promise states in asynchronous tests, enhancing reliability and accuracy.
  • New Features

    • Introduced flushPromises and peekPromiseState for better promise state management in tests.
  • Refactor

    • Replaced instances of promiseState with peekPromiseState across multiple test files to streamline promise state checks.

Copy link

coderabbitai bot commented Sep 15, 2024

Walkthrough

The changes across multiple test files involve replacing the promiseState function from the @lambdalisue/async library with peekPromiseState and flushPromises from the @core/asyncutil library. This update modifies how promise states are checked in asynchronous tests, enhancing the reliability and clarity of assertions related to promise handling. The adjustments are made in various test cases, ensuring that all pending promises are resolved before assertions are executed.

Changes

Files Change Summary
denops/@denops-private/cli_test.ts Replaced promiseState with peekPromiseState, added flushPromises for testing async behavior.
denops/@denops-private/denops_test.ts Updated promiseState to peekPromiseState, introduced flushPromises for better async handling.
denops/@denops-private/host/nvim_test.ts Changed promiseState to peekPromiseState for promise state checking.
denops/@denops-private/host/vim_test.ts Replaced promiseState with peekPromiseState in tests for Vim host.
denops/@denops-private/service_test.ts Updated tests to use peekPromiseState and added flushPromises for async assertions.
tests/denops/testutil/mock_test.ts Replaced promiseState with peekPromiseState, added flushPromises for promise state checks.

Possibly related PRs

🐰 In the land of code where bunnies play,
New functions hop in to brighten the day!
With flushPromises and peek in sight,
Async tests now run with delight!
So let’s cheer for changes, both clever and bright,
In the world of testing, everything feels right! 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aed70a1 and 1dd064a.

Files selected for processing (6)
  • denops/@denops-private/cli_test.ts (7 hunks)
  • denops/@denops-private/denops_test.ts (2 hunks)
  • denops/@denops-private/host/nvim_test.ts (2 hunks)
  • denops/@denops-private/host/vim_test.ts (2 hunks)
  • denops/@denops-private/service_test.ts (15 hunks)
  • tests/denops/testutil/mock_test.ts (5 hunks)
Additional comments not posted (27)
tests/denops/testutil/mock_test.ts (5)

7-7: LGTM!

The import statement change is consistent with the PR objective of replacing the dependency on lambdalisue/async with core/asyncutil.


41-41: LGTM!

The function usage change is consistent with the PR objective of enhancing the accuracy of testing promise states within the codebase.


96-96: LGTM!

The function usage change is consistent with the PR objective of enhancing the accuracy of testing promise states within the codebase.


105-110: LGTM!

The introduction of flushPromises function is consistent with the PR objective of enhancing the accuracy of testing promise states within the codebase. It ensures that all pending promises are resolved before asserting the state of the resultPromise, which enhances the control flow and potentially improves the accuracy of the tests.


146-151: LGTM!

The function usage changes are consistent with the PR objective of enhancing the accuracy of testing promise states within the codebase.

  • The change from promiseState to peekPromiseState indicates a shift in the utility functions used for promise management, which is likely to provide a more efficient or reliable way to check promise states without altering the promise's resolution.
  • The introduction of flushPromises function ensures that all pending promises are resolved before asserting the state of the resultPromise, which enhances the control flow and potentially improves the accuracy of the tests.
denops/@denops-private/denops_test.ts (2)

15-15: LGTM!

The import statement change aligns with the PR objective of replacing the dependency on lambdalisue/async with core/asyncutil. The new imports flushPromises and peekPromiseState from @core/asyncutil library are likely to be used in the test cases to handle promise states more accurately.


363-366: Great improvement to the test case!

The changes to the test case enhance the clarity and reliability of testing the dispatch method of DenopsImpl:

  • Replacing promiseState with peekPromiseState provides a better approach to checking the promise state without awaiting its resolution.
  • Explicitly calling flushPromises() after resolving the waiter ensures that all pending promises are resolved before checking the final state.

These modifications lead to more accurate and reliable test outcomes by properly handling the asynchronous operations.

Also applies to: 368-370

denops/@denops-private/host/vim_test.ts (2)

13-13: LGTM!

The import statement change is consistent with the PR objective and looks good.


381-381: LGTM!

The test case changes are consistent with the import statement change and look good. The peekPromiseState function is being used correctly to check the promise state before and after the session closure.

Also applies to: 388-388

denops/@denops-private/host/nvim_test.ts (2)

403-403: LGTM!

The change from promiseState to peekPromiseState looks good and is consistent with the import statement change. The test case logic remains the same.

Also applies to: 410-410


14-14: LGTM!

The change in import statement and path looks good. Please ensure that the behavior of peekPromiseState is the same as promiseState to avoid any unexpected issues.

Run the following script to verify the behavior of peekPromiseState:

Verification successful

Verification successful: peekPromiseState consistently replaces promiseState

The codebase analysis confirms that peekPromiseState has been consistently implemented across all relevant files, replacing the previous promiseState function. The new function is imported from "jsr:@core/asyncutil@^1.1.1" and is used in the same manner as promiseState, checking promise states in test assertions. The extensive usage in test files suggests that its behavior has been thoroughly verified. No instances of promiseState remain, indicating a complete migration.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of `peekPromiseState` by comparing it with `promiseState`.

# Test: Search for usage of `peekPromiseState` and `promiseState`. Expect: Similar usage patterns.
rg --type typescript $'(peekPromiseState|promiseState)'

Length of output: 91


Script:

#!/bin/bash
# Description: Verify the behavior of `peekPromiseState` by comparing it with `promiseState`.

# Search for usage of `peekPromiseState` and `promiseState` in all files
echo "Searching for peekPromiseState:"
rg 'peekPromiseState'

echo -e "\nSearching for promiseState:"
rg 'promiseState'

# If the above searches don't yield results, try with file extension
echo -e "\nSearching with file extension:"
find . -type f -name "*.ts" -exec grep -Hn 'peekPromiseState\|promiseState' {} +

Length of output: 9208

denops/@denops-private/cli_test.ts (6)

22-22: LGTM!

The imports are consistent with the list of alterations and are likely used to handle asynchronous behavior in the test cases.


266-266: LGTM!

The usage of peekPromiseState is consistent with the import statement and is a valid way to ensure that the main promise is still pending when the listener is closed.


279-279: LGTM!

The usage of peekPromiseState is consistent with the import statement and is a valid way to ensure that the main promise is still pending when the connection is closed.


299-299: LGTM!

The usage of peekPromiseState is consistent with the import statement and is a valid way to ensure that the main promise is fulfilled when the worker stream is closed.


387-387: LGTM!

The usage of peekPromiseState and flushPromises is consistent with the import statement and is a valid way to ensure that the main promise is pending when the connection is closed and fulfilled when the listener is closed. Using flushPromises ensures that all pending promises are resolved before checking the final state of the main promise.

Also applies to: 392-392, 395-395


464-464: LGTM!

The usage of peekPromiseState is consistent with the import statement and is a valid way to ensure that the main promise is fulfilled when the worker stream is closed.

denops/@denops-private/service_test.ts (10)

1072-1073: Excellent usage of the peekPromiseState utility to check the promise state without resolving it.

This allows for precise assertions on the promise state at a specific point in time.


1084-1085: Great consistency in using peekPromiseState across similar sub-tests.

Keeping the assertion style consistent improves the readability and maintainability of the test suite.


1095-1096: Proper assertion for the fulfilled state of the promise.

When the plugin is already loaded, waitLoaded should immediately resolve, which is correctly asserted here.


1106-1107: Good test for the resolution behavior of waitLoaded.

This sub-test ensures that waitLoaded correctly resolves when the plugin is loaded after the call to waitLoaded.


1121-1122: Thorough testing of the waitLoaded behavior in different scenarios.

Testing the promise resolution when waitLoaded is called between load and unload helps cover all possible use cases.


1134-1135: Robust assertion of the promise rejection when the service is closed.

Using peekPromiseState to check the rejected state and assertRejects to verify the rejection reason provides a comprehensive test for this scenario.


1150-1151: Excellent test case for the promise rejection when the service is closed after waitLoaded is called.

This ensures that waitLoaded correctly handles the case where the service is closed while it's waiting for the plugin to load.


1589-1590: Good assertion for the pending state of the waitClosed promise.

Using peekPromiseState allows checking the promise state without resolving it.


1597-1598: Proper use of flushPromises before checking the promise state.

Waiting for all pending promises to resolve using flushPromises ensures a consistent state for the assertion.

Also applies to: 1601-1602


1611-1612: Thorough testing of the waitClosed behavior.

Using flushPromises after closing the service and before checking the promise state helps cover the scenario where waitClosed is called before the service is closed.

Also applies to: 1613-1614


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

codecov bot commented Sep 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.90%. Comparing base (aed70a1) to head (1dd064a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #419   +/-   ##
=======================================
  Coverage   95.90%   95.90%           
=======================================
  Files          24       24           
  Lines        1393     1393           
  Branches      174      174           
=======================================
  Hits         1336     1336           
  Misses         55       55           
  Partials        2        2           

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

@lambdalisue lambdalisue merged commit d3f43a2 into main Sep 16, 2024
9 checks passed
@lambdalisue lambdalisue deleted the asyncutil branch September 16, 2024 09:06
Milly added a commit that referenced this pull request Sep 17, 2024
This is a regression due to #418 and discovered by #419.
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.

2 participants