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

🐛 fix delay in resolving waitLoaded() #420

Merged
merged 3 commits into from
Sep 18, 2024
Merged

🐛 fix delay in resolving waitLoaded() #420

merged 3 commits into from
Sep 18, 2024

Conversation

Milly
Copy link
Contributor

@Milly Milly commented Sep 17, 2024

Fixed delay in resolving waitLoaded().
This is a regression due to #418 and discovered by #419.

And fixed tests for interrupt(), it was a mistake in using assertThrows.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in the service's loading method, enhancing resilience and clarity in asynchronous contexts.
  • New Features

    • Introduced a new Denops plugin that responds to interruption signals, improving interactivity and user experience.
  • Tests

    • Updated test cases to focus on the state of the signal object instead of relying on thrown exceptions, leading to clearer and more maintainable tests.
    • Added comprehensive tests for the denops#interrupt() function, ensuring correct behavior under various server and plugin states.

Copy link

coderabbitai bot commented Sep 17, 2024

Walkthrough

The changes involve modifications to the waitLoaded method in the Service class, enhancing error handling by introducing a try-catch block to manage exceptions. Additionally, the test cases in service_test.ts have been updated to focus on the state of the signal object rather than relying on thrown exceptions. This includes assertions for the signal.aborted property and its reason, streamlining the testing logic. New tests for the denops#interrupt() function and a dummy plugin handling interruptions have also been introduced.

Changes

Files Change Summary
denops/@denops-private/service.ts Modified waitLoaded method to include a try-catch block for error handling, returning a rejected promise instead of throwing errors directly. Removed async keyword.
denops/@denops-private/service_test.ts Updated test cases to remove assertions for thrown exceptions, focusing instead on verifying the signal object's state, including signal.aborted and signal.reason.
denops/@denops-private/denops_test.ts Enhanced tests for DenopsImpl class, adding checks for the denops.interrupted property and its behavior with an AbortController.
tests/denops/runtime/functions/denops/interrupt_test.ts Introduced tests for denops#interrupt() function, validating its behavior under various server and plugin states, and ensuring proper signaling.
tests/denops/testdata/dummy_interrupt_plugin.ts Created a dummy plugin to handle interruption signals, including a reset function to manage state on interruption events.

Possibly related PRs

  • 👍 rejects if the plugin name is invalid #418: The changes in this PR involve modifications to the waitLoaded method in the Service class to include validation for plugin names, which directly relates to the error handling improvements made in the main PR.

Poem

In the meadow where bunnies play,
Changes hop in a bright array.
Errors caught in gentle embrace,
Tests now dance in a clearer space.
With each leap, we celebrate,
A code so fine, we elevate! 🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0035db and 8b02b1b.

Files selected for processing (3)
  • denops/@denops-private/denops_test.ts (2 hunks)
  • tests/denops/runtime/functions/denops/interrupt_test.ts (1 hunks)
  • tests/denops/testdata/dummy_interrupt_plugin.ts (1 hunks)
Additional comments not posted (11)
tests/denops/testdata/dummy_interrupt_plugin.ts (2)

3-17: LGTM!

The main function is well-structured and follows good practices:

  • It correctly sets up an event listener for the denops.interrupted signal.
  • The reset function is defined and called appropriately.
  • Making the reset function accessible through the denops.dispatcher object is a good practice for allowing external calls to reset the plugin's state.

The implementation looks accurate and error-free.


4-11: LGTM!

The reset function is well-implemented:

  • It correctly sets up an event listener for the denops.interrupted signal.
  • Executing a command to run an autocmd when an "abort" event is triggered is an appropriate way to notify that the plugin has been interrupted.
  • Including the reason for the interruption in the autocmd provides useful information for debugging.
  • Setting the once option to true is a good practice to ensure that the listener is only triggered once, preventing multiple executions.

The implementation looks accurate and error-free.

tests/denops/runtime/functions/denops/interrupt_test.ts (5)

20-24: LGTM!

The test case correctly verifies the behavior of denops#interrupt() when the server is not running.


30-34: LGTM!

The test case correctly verifies the behavior of denops#interrupt() when the plugin is not loaded.


50-52: LGTM!

The test case correctly verifies that denops#interrupt() returns immediately when the plugin is loaded.


54-65: LGTM!

The test case correctly verifies that denops#interrupt() sends the appropriate signal to the plugin when it is interrupted.


69-80: LGTM!

The test case correctly verifies that denops#interrupt() sends the appropriate signal to the plugin with the provided reason when it is interrupted.

denops/@denops-private/denops_test.ts (4)

Line range hint 3-9: LGTM!

The additional imports from @std/assert module look good. They will be useful for making assertions in the test cases.


34-39: Looks good!

The introduction of the serviceInterrupt controller and setting service.interrupted to its signal is a nice way to manage and test the interrupt behavior of the service in the tests.


42-56: Great test additions!

The new test step for the .interrupted property looks excellent:

  • It verifies that the property returns an AbortSignal instance.
  • It comprehensively tests the abort functionality by checking the signal state before and after aborting, as well as verifying the abort reason.

The test steps are well-structured and cover the key aspects of the interruption behavior. Nice work!


Line range hint 3-9: This code segment is a duplicate of the one at the same line range reviewed earlier.


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 generate interesting stats about this repository and render them as a table.
    -- @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 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.97%. Comparing base (d0718c2) to head (8b02b1b).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #420      +/-   ##
==========================================
+ Coverage   95.96%   95.97%   +0.01%     
==========================================
  Files          25       25              
  Lines        1412     1416       +4     
  Branches      179      180       +1     
==========================================
+ Hits         1355     1359       +4     
  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 f9ab988 into main Sep 18, 2024
16 checks passed
@lambdalisue lambdalisue deleted the fix-service branch September 18, 2024 03:26
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
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