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

toBe hangs for cyclic structures #7429

Open
6 tasks done
yangshun opened this issue Feb 5, 2025 · 5 comments
Open
6 tasks done

toBe hangs for cyclic structures #7429

yangshun opened this issue Feb 5, 2025 · 5 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@yangshun
Copy link

yangshun commented Feb 5, 2025

Describe the bug

Not much to say here, Vitest just doesn't complete when I have a certain test case for an algo question, it hangs indefinitely.

No async operations involved.

I don't think it's a bug with my algo because I'm migrating from Jest which is able to successfully run all the test cases.

> jest "algo/graph-clone"

 PASS  algo/graph-clone/setup/src/graph-clone.test.ts

Test Suites: 2 passed, 2 total
Tests:       103 passed, 103 total
Snapshots:   0 total
Time:        1.786 s

With Vite it doesn't complete:

~/projects/vitejs-vite-jtzpyjuo 5s
❯ npm t

> [email protected] test
> vitest run


 RUN  v3.0.5 /home/projects/vitejs-vite-jtzpyjuo


 ❯ src/graph-clone.test.ts 0/8

 Test Files 0 passed (1)
      Tests 0 passed (8)
   Start at 08:44:17
   Duration 83.05s

Reproduction

https://stackblitz.com/edit/vitejs-vite-jtzpyjuo

This is a minimal repro with 8 test cases (tests.json). My original code has 100 test cases (tests.all.json).

If the last test case in tests.json is removed (L240-L384), the tests can complete.

System Info

❯ npx envinfo --system --npmPackages '{vitest*,@vitest/*,vite,@vitejs/*,playwright,webdriverio}' --binaries --browsers
Need to install the following packages:
[email protected]
Ok to proceed? (y) y

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^6.0.11 => 6.0.11 
    vitest: ^3.0.5 => 3.0.5

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 5, 2025

Just in case, can you confirm it's not your algo getting stuck in while loop or recursion?

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 5, 2025

As explained in #1405, if synchronous code is taking over, then timeout doesn't kick in. You can try --disableConsoleIntercept + console.log("debug") to see if synchronous code is running in loop.

@yangshun
Copy link
Author

yangshun commented Feb 5, 2025

Just in case, can you confirm it's not your algo getting stuck in while loop or recursion?

Yes it should not be, I am currently using Jest and it passes fine. I encountered the hanging issue while migrating to Vitest.

I did further debugging and narrowed down the issue to this line expect(clonedGraph).not.toBe(originalGraph). Commenting out this line will let the test end.

I suspect the implementation of the toBe assertion could be buggy.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 5, 2025

I did further debugging and narrowed down the issue to this line expect(clonedGraph).not.toBe(originalGraph). Commenting out this line will let the test end.

I suspect the implementation of the toBe assertion could be buggy.

Okay, that's likely a bug of printing/diffing a cyclic object getting stuck in the loop.

@hi-ogawa hi-ogawa added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Feb 5, 2025
@yangshun
Copy link
Author

yangshun commented Feb 5, 2025

Thanks. As a workaround I've changed my code to expect(Object.is(clonedGraph, originalGraph)).toBe(false);

Updated StackBlitz repro to the minimal test case: https://stackblitz.com/edit/vitejs-vite-jtzpyjuo?file=src%2Fgraph.test.ts

@yangshun yangshun changed the title Vitest hangs for certain test case toBe hangs for cyclic structures Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants