Skip to content

maxConcurrency is not respected in beforeAll/afterAll hooks #8367

@BarrensZeppelin

Description

@BarrensZeppelin

Describe the bug

More than maxConcurrency number of hooks can run in parallel.

Reproduction

package.json

{
  "name": "vitest",
  "version": "1.0.0",
  "description": "",
  "license": "ISC",
  "author": "",
  "type": "commonjs",
  "devDependencies": {
    "vitest": "^3.2.4"
  }
}

a.test.js

import { beforeAll, describe, it } from 'vitest';

async function sleep(ms=1000) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

describe.concurrent('Test Suite', () => {
    describe.for(["a", "b"])('$0', (name) => {
        beforeAll(async () => {
            console.log(`Running beforeAll for ${name}`);
            await sleep();
        });

        it(`test ${name} 1`, async () => {
        });
    });
});
$ npm exec -- vitest run --max-concurrency=1 a.test.js

 RUN  v3.2.4 <snip>

stdout | a.test.js > Test Suite > 'b'
Running beforeAll for a
Running beforeAll for b

 ✓ a.test.js (2 tests) 1008ms
   ✓ Test Suite > 'a' > test a 1 2ms
   ✓ Test Suite > 'b' > test b 1 0ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  09:50:21
   Duration  1.26s (transform 17ms, setup 0ms, collect 12ms, tests 1.01s, environment 0ms, prepare 59ms)

I would expect the test to run for at least 2 seconds, because the calls to sleep should not be run in parallel with --max-concurrency=1.

System Info

Not relevant

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

Labels

p3-minor-bugAn edge case that only affects very specific usage (priority)

Type

Projects

Status

Approved

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions