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: rpc timeout error messages to include caller #5103

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

AriPerkkio
Copy link
Member

Description

Improves error messages caused by birpc timeouts. Currently it can be difficult to track down a birpc timeout error as those are used in multiple modules. This PR extends the error message to include the caller in Vitest's context. The test runner's RPC also adds arguments of some known functions.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Feb 2, 2024

Deploy Preview for fastidious-cascaron-4ded94 ready!

Name Link
🔨 Latest commit 8e16d65
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65bd13ae94ca270009d53e53
😎 Deploy Preview https://deploy-preview-5103--fastidious-cascaron-4ded94.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@AriPerkkio AriPerkkio changed the title fix: rpc timeout error messages to log caller fix: rpc timeout error messages to include caller Feb 2, 2024
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Looks good!
I tested locally by patching fetch and timeout:

Show diff
diff --git a/packages/vitest/src/node/pools/rpc.ts b/packages/vitest/src/node/pools/rpc.ts
index 3144e3c7..7fe3fdb5 100644
--- a/packages/vitest/src/node/pools/rpc.ts
+++ b/packages/vitest/src/node/pools/rpc.ts
@@ -20,7 +20,11 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
       const r = await project.vitenode.transformRequest(id)
       return r?.map as RawSourceMap | undefined
     },
-    fetch(id, transformMode) {
+    async fetch(id, transformMode) {
+      if (id === "/@vite/env") {
+        console.log("sleeping...")
+        await new Promise(resolve => setTimeout(resolve, 2_000))
+      }
       return project.vitenode.fetchModule(id, transformMode)
     },
     resolveId(id, importer, transformMode) {
diff --git a/packages/vitest/src/runtime/rpc.ts b/packages/vitest/src/runtime/rpc.ts
index c5723f2d..fed0f5c3 100644
--- a/packages/vitest/src/runtime/rpc.ts
+++ b/packages/vitest/src/runtime/rpc.ts
@@ -76,6 +76,7 @@ export function createRuntimeRpc(options: Pick<BirpcOptions<RuntimeRPC>, 'on' |
         throw new Error(message)
       },
       ...options,
+      timeout: 1_000
     },
   ))
$ pnpm -C test/core test basic.test.ts

> @vitest/test-core@ test /home/hiroshi/code/others/vitest/test/core
> vitest "basic.test.ts"


 DEV  v1.2.2 /home/hiroshi/code/others/vitest/test/core

sleeping...

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: [vitest-worker]: Timeout calling "fetch" with "["/@vite/env","ssr"]"
 ❯ Object.onTimeoutError ../../packages/vitest/dist/vendor/rpc._cY2a4B3.js:58:15
 ❯ Timeout._onTimeout ../../packages/vitest/dist/vendor/index.8bPxjt7g.js:39:41
 ❯ listOnTimeout node:internal/timers:573:17
 ❯ process.processTimers node:internal/timers:514:7

@sheremet-va sheremet-va merged commit a6e04bd into vitest-dev:main Feb 5, 2024
19 checks passed
@AriPerkkio AriPerkkio deleted the fix/birpc-errors branch February 5, 2024 12:06
@sheremet-va sheremet-va added this to the 1.3.0 milestone Feb 9, 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.

None yet

3 participants