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

Asynchronous fixtures used concurrently cause Vitest to hang #4402

Closed
6 tasks done
dsyddall opened this issue Oct 31, 2023 · 1 comment · Fixed by #4403
Closed
6 tasks done

Asynchronous fixtures used concurrently cause Vitest to hang #4402

dsyddall opened this issue Oct 31, 2023 · 1 comment · Fixed by #4403

Comments

@dsyddall
Copy link
Contributor

dsyddall commented Oct 31, 2023

Describe the bug

Given a test with an asynchronously resolved fixture, Vitest hangs when the fixture is used in multiple tests concurrently.

Example test:

import { expect, test } from 'vitest';

const myTest = test.extend<{ a: number }>({
  a: async ({ task }, use) => {
    await new Promise<void>((resolve) => setTimeout(resolve, 200));

    console.log('running test', task.id);
    await use(0);
    console.log('cleaning up test', task.id);
  },
});

myTest.concurrent('fixture - test 1', ({ a }) => {
  expect(a).toBe(0);
});

myTest.concurrent('fixture - test 2', ({ a }) => {
  expect(a).toBe(0);
});

Results of the test:

 DEV  v1.0.0-beta.3 /home/projects/vitest-dev-vitest-9d9pqh
      UI started at http://localhost:51204/__vitest__/

stdout | test/async-fixture.test.ts > fixture - test 2
running test 1084931944_0
running test 1084931944_1
cleaning up test 1084931944_1

 ❯ test/async-fixture.test.ts (2)
   ✓ fixture - test 1
   ✓ fixture - test 2

The first test fixture is never cleaned up, and since the promise returned from the call to use() never resolves, Vitest hangs.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-9d9pqh?file=test%2Fasync-fixture.test.ts

System Info

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.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.9.2 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: 1.0.0-beta.3 => 1.0.0-beta.3 
    vite: latest => 4.5.0 
    vitest: 1.0.0-beta.3 => 1.0.0-beta.3

Used Package Manager

pnpm

Validations

@stackblitz
Copy link

stackblitz bot commented Oct 31, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

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

Successfully merging a pull request may close this issue.

1 participant