diff --git a/packages/vitest/src/node/pools/pool.ts b/packages/vitest/src/node/pools/pool.ts index 13cc822e5..dd14bd48f 100644 --- a/packages/vitest/src/node/pools/pool.ts +++ b/packages/vitest/src/node/pools/pool.ts @@ -80,6 +80,8 @@ export class Pool { let isMemoryLimitReached = false const runner = this.getPoolRunner(task, method) + // `setMaxWorkers` can replace the map for the next group before this id is freed + const workerIds = this.workerIds const poolId = runner.poolId ?? this.getConcurrencyId() runner.poolId = poolId @@ -195,7 +197,7 @@ export class Pool { ) } - this.freeWorkerId(poolId) + workerIds.set(poolId, true) } // This is mostly to avoid zombie workers when/if Vitest internals run into errors diff --git a/test/e2e/test/group-order.test.ts b/test/e2e/test/group-order.test.ts index 4cb3d1a0d..158dff2b4 100644 --- a/test/e2e/test/group-order.test.ts +++ b/test/e2e/test/group-order.test.ts @@ -58,3 +58,82 @@ test('tests run according to the group order', async () => { ✓ |1| example.1.test.ts > 1