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

🌿 add/improve tests for interrupt #422

Merged
merged 7 commits into from
Sep 24, 2024
Merged

🌿 add/improve tests for interrupt #422

merged 7 commits into from
Sep 24, 2024

Conversation

Milly
Copy link
Contributor

@Milly Milly commented Sep 17, 2024

This is fixed re-opened PR of #421.

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive test suite for the denops#interrupt() function to validate its behavior under various conditions.
    • Added a dummy plugin to manage interruption signals, enhancing interactivity within the Denops environment.
    • Implemented new tests for the denops#notify() and denops#request_async() functions to ensure robust error handling and event validation.
    • Added a new dispatcher plugin to simulate asynchronous requests and improve event handling in tests.
    • Enhanced the testing of the DenopsImpl class with improved interruption logic validation.
  • Bug Fixes

    • Improved the robustness of the tests for various functions, ensuring thorough validation of error handling.
  • Documentation

    • Enhanced test structure for better clarity and coverage of interrupt functionality.

@Milly Milly marked this pull request as draft September 17, 2024 15:56
Copy link

coderabbitai bot commented Sep 17, 2024

Walkthrough

The changes introduce enhancements to the testing of the DenopsImpl class and the denops#interrupt() function, along with the creation of new Denops plugins. The updates include the addition of tests for interruption handling, the implementation of an AbortController, and the establishment of dummy plugins that respond to interruption signals and notifications. These modifications aim to improve the reliability and functionality of the Denops framework.

Changes

Files Change Summary
denops/@denops-private/denops_test.ts Enhanced testing for DenopsImpl with AbortController, validating the .interrupted property and its behavior upon triggering interruptions.
tests/denops/runtime/functions/denops/interrupt_test.ts Introduced tests for denops#interrupt() function, covering scenarios for server status and plugin loading, ensuring correct behavior and event triggering for interruptions.
tests/denops/runtime/functions/denops/notify_test.ts Modified tests for denops#notify() function to use a new dispatcher plugin, adding checks for error handling and ensuring notifications behave correctly under various conditions.
tests/denops/runtime/functions/denops/request_async_test.ts Enhanced tests for denops#request_async() function, refining event handling and validating success and failure scenarios with a new dispatcher plugin.
tests/denops/runtime/functions/denops/request_test.ts Updated tests for denops#request() function to focus on the new dispatcher plugin, ensuring correct method invocation and error handling for non-existent methods.
tests/denops/testdata/dummy_dispatcher_plugin.ts Introduced a new Denops plugin that handles a command called test, asynchronously executing a Vim command and triggering an autocommand event.
tests/denops/testdata/dummy_interrupt_plugin.ts Added a new Denops plugin that manages interruption signals, executing commands based on the reason for interruption and exposing a reset function for managing interruption handling.

Possibly related PRs

  • 🌿 add module that resolves testdata path or URL #417: This PR introduces a module for resolving test data paths or URLs, which is relevant as the main PR enhances testing for the DenopsImpl class, potentially utilizing the new path resolution capabilities.
  • 🐛 fix delay in resolving waitLoaded() #420: This PR addresses a delay in the waitLoaded() function and includes corrections to tests for the interrupt() function, which aligns with the main PR's focus on improving the robustness of tests related to interruption handling in the Denops framework.

Suggested reviewers

  • coderabbitai

🐇 In the land of Denops, where signals play,
New tests and plugins brighten the day.
With interrupts handled, oh what a delight,
Our code hops forward, taking flight!
Let’s celebrate changes, both big and small,
For a robust framework, we’ll stand tall! 🎉


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a54da8 and 5a22b02.

Files selected for processing (5)
  • tests/denops/runtime/functions/denops/interrupt_test.ts (1 hunks)
  • tests/denops/runtime/functions/denops/notify_test.ts (3 hunks)
  • tests/denops/runtime/functions/denops/request_async_test.ts (3 hunks)
  • tests/denops/testdata/dummy_dispatcher_plugin.ts (1 hunks)
  • tests/denops/testdata/dummy_interrupt_plugin.ts (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • tests/denops/runtime/functions/denops/interrupt_test.ts
  • tests/denops/runtime/functions/denops/notify_test.ts
  • tests/denops/testdata/dummy_dispatcher_plugin.ts
  • tests/denops/testdata/dummy_interrupt_plugin.ts
Additional comments not posted (13)
tests/denops/runtime/functions/denops/request_async_test.ts (13)

1-4: LGTM!

The additional imports from the jsr:@std/assert module are relevant and appropriate for the test file.


11-11: LGTM!

The renaming of scriptValid to scriptDispatcher aligns with the introduction of the dummy_dispatcher_plugin.ts file and provides a more descriptive name for the constant.


24-24: LGTM!

The addition of the autocommand to capture events triggered by the dummy_dispatcher_plugin is a valid approach to track and verify the event handling and callback mechanisms in the tests.


26-26: LGTM!

The modification of the TestDenopsRequestAsyncSuccess function to include the :Called suffix in the event name aligns with the updated event naming convention and improves clarity in the test assertions.


29-29: LGTM!

The modification of the TestDenopsRequestAsyncFailure function to include the :Called suffix in the event name aligns with the updated event naming convention and improves clarity in the test assertions.


53-53: LGTM!

The update to use the g:__test_denops_events variable in the assertion is correct and ensures that the captured events are being verified.


56-56: LGTM!

The update to the event name in the assertion to include the :Called suffix aligns with the updated event naming convention and ensures that the failure callback invocation is verified correctly.


74-74: LGTM!

Loading the dummy_dispatcher_plugin using the scriptDispatcher constant ensures that the correct plugin script is used for testing and aligns with the previous renaming of the constant.


78-78: LGTM!

Updating the condition to check for the DenopsPluginPost:dummy event ensures that the test waits for the plugin to be loaded before proceeding, and the event name is consistent with the plugin loading mechanism.


81-95: LGTM!

The addition of the new test step to verify that denops#request_async returns immediately is a valid assertion. By clearing the g:__test_denops_events variable before making the request and asserting that it remains empty immediately after, the test ensures that the function does not block and returns control to the caller.


98-104: LGTM!

The addition of the new test step to verify that the dispatcher method is called is a valid assertion. By waiting for the g:__test_denops_events variable to have at least one event and asserting that the DummyDispatcherPlugin:TestCalled:["foo"] event is included, the test ensures that the dispatcher method is invoked correctly with the provided arguments.


106-116: LGTM!

The addition of the new test step to verify that the success callback is called is a valid assertion. By asserting that the TestDenopsRequestAsyncSuccess:Called event is included in the captured events and verifying the arguments passed to the callback, the test ensures that the success callback is invoked correctly with the expected data structure.


118-149: LGTM!

The addition of the new test scenario to verify the behavior when the dispatcher method does not exist is a comprehensive assertion. It covers the following aspects:

  1. Verifying that denops#request_async returns immediately even when the method does not exist.
  2. Ensuring that the failure callback is invoked in such cases.
  3. Asserting that the correct error message is passed to the failure callback.

This test scenario enhances the robustness of the test suite by covering the error path and validating the expected behavior.


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 (f9ab988) to head (5a22b02).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #422   +/-   ##
=======================================
  Coverage   95.97%   95.97%           
=======================================
  Files          25       25           
  Lines        1416     1416           
  Branches      180      180           
=======================================
  Hits         1359     1359           
  Misses         55       55           
  Partials        2        2           

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

Base automatically changed from fix-service to main September 18, 2024 03:26
@Milly Milly marked this pull request as ready for review September 18, 2024 03:49
@Milly
Copy link
Contributor Author

Milly commented Sep 18, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Sep 18, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Milly
Copy link
Contributor Author

Milly commented Sep 18, 2024

I've included fixes for flaky tests for denops#notify etc.

@Milly Milly marked this pull request as draft September 18, 2024 04:37
@Milly Milly marked this pull request as ready for review September 18, 2024 05:09
Copy link
Member

@lambdalisue lambdalisue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lambdalisue lambdalisue merged commit 08146a5 into main Sep 24, 2024
9 checks passed
@lambdalisue lambdalisue deleted the interrupt-test branch September 24, 2024 19:55
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