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: don't close used mock agent #170

Merged
merged 3 commits into from
Jul 2, 2024
Merged

fix: don't close used mock agent #170

merged 3 commits into from
Jul 2, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jul 2, 2024

avoid ClientDestroyedError

ClientDestroyedError: The client is destroyed
      at Agent.dispatch (node_modules/undici/lib/dispatcher-base.js:172:15)
      at MockAgent.dispatch (node_modules/undici/lib/mock/mock-agent.js:65:25)
      at MockAgent.request (node_modules/undici/lib/api/api-request.js:169:10)

Summary by CodeRabbit

  • Refactor
    • Improved the control flow in the restore() method to enhance function execution order.
    • Streamlined logic in agent management for better clarity and efficiency.

avoid ClientDestroyedError

```bash
ClientDestroyedError: The client is destroyed
      at Agent.dispatch (node_modules/undici/lib/dispatcher-base.js:172:15)
      at MockAgent.dispatch (node_modules/undici/lib/mock/mock-agent.js:65:25)
      at MockAgent.request (node_modules/undici/lib/api/api-request.js:169:10)
```
@fengmk2 fengmk2 added the bug label Jul 2, 2024
Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

This update refactors the restore() method in index.js to alter the control flow, and in lib/mock_agent.js, it streamlines logic for handling APP_HTTPCLIENT_AGENT and adjusts the restore method. The changes aim to improve code clarity and efficiency.

Changes

Files Change Summary
index.js Modified the restore() method to change the order of function calls and return statements.
lib/mock_agent.js Refactored getAgent(app) and restore(app) methods to streamline logic for handling dispatcher and agent instances.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant App
    participant MockAgent
    participant Cluster
    participant MM

    User ->> App: Call restore()
    App ->> Cluster: Call restore()
    Cluster -->> App: Restoration done
    App ->> MockAgent: Call restore(app)
    MockAgent -->> App: Restoration done
    App ->> MM: Call restore()
    MM -->> App: Restoration done
    App -->> User: Return from restore()
Loading

Poem

In code’s enchanted forest deep,
Functions dance and methods leap,
Refactored lines, more clear and bright,
Restoring flows both day and night.
Efficient paths, our goal in view,
A coder’s dream is coming true.
🐇✨


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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

pkg-pr-new bot commented Jul 2, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: fe8bc96

egg-mock

npm i https://pkg.pr.new/eggjs/egg-mock@170


templates

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 95666e1 and cbee62e.

Files selected for processing (2)
  • index.js (1 hunks)
  • lib/mock_agent.js (2 hunks)
Additional comments not posted (3)
lib/mock_agent.js (2)

11-14: LGTM!

The changes ensure that the raw dispatcher is saved if not already set. This is a good addition to ensure the dispatcher is not lost.


25-32: LGTM!

The changes improve the logic for setting the dispatcher, ensuring that the correct dispatcher is restored.

index.js (1)

25-26: LGTM!

The change ensures that mm.restore is called after restoring the cluster and mock agent. This sequence is logical and ensures all other restores are completed before calling the final restore.

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.49%. Comparing base (ddab25f) to head (fe8bc96).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #170      +/-   ##
==========================================
- Coverage   85.51%   85.49%   -0.03%     
==========================================
  Files          27       27              
  Lines        2623     2619       -4     
  Branches      472      474       +2     
==========================================
- Hits         2243     2239       -4     
  Misses        380      380              

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

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 cbee62e and 451661d.

Files selected for processing (1)
  • lib/mock_agent.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • lib/mock_agent.js

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 451661d and fe8bc96.

Files selected for processing (1)
  • index.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • index.js

@fengmk2 fengmk2 merged commit 3e7a504 into master Jul 2, 2024
13 of 14 checks passed
@fengmk2 fengmk2 deleted the fix-httpclient-mock branch July 2, 2024 14:44
fengmk2 pushed a commit that referenced this pull request Jul 2, 2024
[skip ci]

## [5.12.3](v5.12.2...v5.12.3) (2024-07-02)

### Bug Fixes

* don't close used mock agent ([#170](#170)) ([3e7a504](3e7a504))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant