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

Duplicate VITEST_POOL_ID #1576

Closed
6 tasks done
flunderpero opened this issue Jun 30, 2022 · 9 comments
Closed
6 tasks done

Duplicate VITEST_POOL_ID #1576

flunderpero opened this issue Jun 30, 2022 · 9 comments

Comments

@flunderpero
Copy link

Describe the bug

We see duplicate VITEST_POOL_ID in our test suite.

The following output is created by logging in beforeAll and afterAll like this:
console.log("VITEST_POOL_ID", process.env.VITEST_POOL_ID, process.env.VITEST_WORKER_ID, performance.now())

The output:

VITEST_POOL_ID BEFORE 5 5 1879.1254999637604
VITEST_POOL_ID BEFORE 1 1 1865.7593338489532
VITEST_POOL_ID BEFORE 7 7 1861.8154590129852
VITEST_POOL_ID BEFORE 8 8 1861.237958908081
VITEST_POOL_ID AFTER 7 7 2069.352292060852
VITEST_POOL_ID AFTER 8 8 2106.785749912262
VITEST_POOL_ID BEFORE 1 9 2140.8526248931885
VITEST_POOL_ID BEFORE 1 10 2357.5155839920044
VITEST_POOL_ID BEFORE 1 11 2473.89066696167
VITEST_POOL_ID AFTER 1 1 2993.181624889374
VITEST_POOL_ID BEFORE 3 16 3702.6203339099884
VITEST_POOL_ID AFTER 3 16 3935.632458925247
VITEST_POOL_ID BEFORE 1 17 3931.5376670360565
VITEST_POOL_ID AFTER 1 17 3970.2642500400543
VITEST_POOL_ID BEFORE 1 18 4274.482708930969
VITEST_POOL_ID AFTER 1 18 4356.533874988556
VITEST_POOL_ID AFTER 1 10 10438.08066701889
VITEST_POOL_ID AFTER 1 9 13164.534374952316
VITEST_POOL_ID AFTER 1 11 13179.464833974838

You can clearly see in line 7 to 9 that VITEST_POOL_ID of 1 is used in parallel.

Our vite.config.ts:

export default defineConfig({
    test: {
        setupFiles: ["packages/lib.shared.test/test_setup.ts"],
        threads: true,
        testTimeout: 8000,
        hookTimeout: 10000,
        minThreads: 8,
        maxThreads: 8,
        coverage: false,
    },
    esbuild: {
        target: "node16",
    },
})

We ever only see VITEST_POOL_ID of 1 being used in parallel. I checked that VITEST_POOL_ID matches import {workerId} from "titnypool".

Reproduction

Currently I am trying to reproduce the error in tinypool, but did not manage to do so.

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 8.70 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    Yarn: 3.1.0 - ~/.nvm/versions/node/v16.15.1/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
  Browsers:
    Chrome: 103.0.5060.53
    Firefox: 100.0.2
    Safari: 15.5
  npmPackages:
    vitest: 0.16.0 => 0.16.0

Used Package Manager

yarn

Validations

@Aslemammad
Copy link
Member

Since there is no reproduction, What I recommend is trying to debug your app with ndb and see if you can find a solution!

@Lyokolux
Copy link

Lyokolux commented Jul 13, 2022

Hey ! I am currently running (integration) test suits against multiple sqlite databases at the same time. Thus the tests are concurrent depending of the core of the machine.

I duplicate the original one and assign them different ids. I used first VITEST_POOL_ID but the ids have clashed.

I concluded VITEST_POOL_ID is not unique. However I used VITEST_WORKER_ID and it worked like a charm.

I will provide a reproduction :) Give me some time.

My strategy for a reproduction:

  • writing multiple test suits with 1-3 dummy tests in it
  • creating a file named VITEST_POOL_ID for each test suits (in the setupFile)
  • check if there is some duplicates

@Lyokolux
Copy link

Lyokolux commented Jul 14, 2022

Here the reproduction based on a Nuxt 3 template: https://stackblitz.com/edit/nuxt-starter-agwwgz?file=test%2FsetupIntegration.ts,vitest.config.ts

Workflow:

  • Run yarn test → we see files created in a pool-ids directory
  • Clean directory (to run it again): yarn test:clean

What we observe?

  • pool-ids directory contains the generated file, 2 for each test suit / test file.
    • pool-x-yyyyyy... with x the VITEST_POOL_ID
    • worker-x-yyyyyy...with x the VITEST_WORKER_ID

Remarks:

  • there is multiple threads and it runs in isolated "mode". Check vitest.config.ts to be sure of it.

Constat:

  • VITEST_POOL_ID is repeated
  • VITEST_WORKER_ID seems unique (work in this case and mine in my project, proof need to be made)

@sheremet-va
Copy link
Member

VITEST_WORKER_ID seems unique (work in this case and mine in my project, proof need to be made)

VITEST_WORKER_ID is always unique, and it will increase with each watcher trigger.

@Lyokolux
Copy link

Lyokolux commented Jul 14, 2022

VITEST_WORKER_ID seems unique (work in this case and mine in my project, proof need to be made)

VITEST_WORKER_ID is always unique, and it will increase with each watcher trigger.

Ok also the point in the documentation is unclear about that in https://vitest.dev/config/#setupfiles:

You can use process.env.VITEST_POOL_ID (integer-like string) inside to distinguish between threads (will always be '1', if run with threads: false).

VITEST_POOL_ID is then not unique, on the contrary of VITEST_WORKER_ID. It could be useful to mention that uniqueness of VITEST_WORKER_ID.

Also "We see duplicate VITEST_POOL_ID in our test suite." is an expected behavior.
However, "We see duplicate VITEST_POOL_ID running in parallel in our test suite." is not.

To get a unique ID for each thread, VITEST_WORKER_ID should be used.
Right @flunderpero ?

@sheremet-va
Copy link
Member

No, it is not expected behaviour. VITEST_WORKER_ID is generated by Vitest whenever we fire up a worker. VITEST_POOL_ID should be unique while running tests (it's a queue, when one worker is removed, we can reuse it's ID). See: #1469

@Aslemammad
Copy link
Member

I created a test and I guess I fixed it, it's a challenging issue! But one thing, @Lyokolux tests were helpful but they don't test the behaviour, because there's a misunderstanding there, and it's that VITEST_POOL_ID can be repeated, no problem with that, but it cannot be repeated at the same two running workers or more!

I'll release a new tinypool version soon!

@Aslemammad
Copy link
Member

Aslemammad commented Jul 16, 2022

I expect this to be resolved in tinypool@^0.2.3

cc @flunderpero

@Aslemammad
Copy link
Member

feel free to re-open in case you faced the issue again!

@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2023
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

4 participants