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

vitest with prisma failing randomly in CI #6635

Closed
6 tasks done
formatlos opened this issue Oct 3, 2024 · 3 comments
Closed
6 tasks done

vitest with prisma failing randomly in CI #6635

formatlos opened this issue Oct 3, 2024 · 3 comments

Comments

@formatlos
Copy link

Describe the bug

We are currently migrating our test-suite from jest to vitest. Everything runs smoothly locally, but on CI (Gitlab ci with k8s runner in our k8s cluster) the tests fail randomly every second or third run.

We have almost 1000 test across 115 test files, when it fails it's 1 or 2 random testfiles having one of the following errors:

Error: Cannot find module '.prisma/client/default'
Require stack:
- /xxx/node_modules/@prisma/client/default.js

or

⎯⎯⎯⎯⎯⎯ 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 Rejection ⎯⎯⎯⎯⎯
PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "debian-openssl-3.0.x".
This is likely caused by tooling that has not copied "libquery_engine-debian-openssl-3.0.x.so.node" to the deployment folder.
Ensure that you ran `prisma generate` and that "libquery_engine-debian-openssl-3.0.x.so.node" has been copied to "node_modules/.prisma/client".
We would appreciate if you could take the time to share some information with us.
Please help us by answering a few questions: https://pris.ly/engine-not-found-tooling-investigation
The following locations have been searched:
  /builds/xxx/node_modules/.prisma/client
  /builds/xxx/node_modules/@prisma/client
  /tmp/prisma-engines
  /builds/xxx/prisma

The files it can't find are in the node_modules folder.

We are already running with --pool=forks and tried different settings in regards to poolOptions, but still the same behaviour.
We did also compare the modules dump of a failed and successful run (which was exactly the same).

Any ideas how to solve that?

Reproduction

Run vitest in gitlab ci with a test suite using prisma

System Info

System:
    OS: Linux 5.10 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (8) x64 Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
    Memory: 28.55 GB / 30.99 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 22.9.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.8.2 - /usr/bin/npm
  npmPackages:
    @vitest/coverage-istanbul: ^2.1.1 => 2.1.1 
    vitest: ^2.1.1 => 2.1.1

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Oct 3, 2024

Can't really help without a reproduction. Maybe you are removing the prisma folder or regenerating it during a test? So when another test runs in parallel, the folder is no longer there. Try running tests with --single-worker (much slower) and --no-isolate (tests might break if they rely on a shared state). You can also try running tests with the --sequence.shuffle to randomise the order - this also prints the seed that you can run with the next time to reproduce it more reliably.

Copy link

github-actions bot commented Oct 3, 2024

Hello @formatlos. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@formatlos
Copy link
Author

thanks @sheremet-va for your quick response.

I did find the issue: we do some parallel, transactional testing therefore we need to run migrations within each worker. We call prisma migrate reset but this does re-generate the client implicitly if not skipped with --skip-generate.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants