-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
concurrent.each executes iterations serially instead of concurrently #5458
Comments
@sheremet-va told me on Discord:
If I understand correctly, the collection phase executes each What I don't get is why for 2 given Executing all the tests concurrently, no matter their Consider this test file: import { test, describe } from 'vitest';
const cases = [1, 2, 3];
describe.concurrent.each(cases)('case %i', () => {
test('first', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test('second', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
}); With the current implementation, running all the tests would take ~30 seconds (3 describe blocks of 10 seconds each ran one after the other). Ideally, I would expect all 6 generated tests (3 describe blocks x 2 tests) to be all run concurrently, which would reduce the total time to ~10s. I guess the user-land solution is to ban import { test, describe } from 'vitest';
const cases = [1, 2, 3];
for (const case of cases) {
test(`case ${case} > first`, async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test(`case ${case} > second`, async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
} 10 seconds total for these to run. 👆 |
I think this is not necessary about https://stackblitz.com/edit/vitest-dev-vitest-fsag3t?file=test%2Fsuite.test.ts // takes 2 sec
describe.concurrent("not ok", () => {
describe("1st suite", () => {
test("inner", async () => {
await sleep(1000)
})
});
describe("2nd suite", () => {
test("inner", async () => {
await sleep(1000)
})
});
});
// takes 1 sec
describe.concurrent("ok", () => {
test("1st case", async () => {
await sleep(1000)
})
test("2nd case", async () => {
await sleep(1000)
})
}); I think, currently // takes 2 sec
describe("not ok", () => {
describe("1st suite", () => {
test.concurrent("inner", async () => {
await sleep(1000)
})
});
describe("2nd suite", () => {
test.concurrent("inner", async () => {
await sleep(1000)
})
});
}); Also, considering describe.concurrent.each([1, 2])('case %i', () => {
test('first', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test('second', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
});
// ⇓
describe('case 1', () => {
test.concurrent('first', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test.concurrent('second', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
});
describe('case 2', () => {
test.concurrent('first', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test.concurrent('second', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
}); |
@hi-ogawa Sorry I just edited my post while you were writing yours lol So in the end for max concurrency, describe blocks should be avoided and one should use a regular import { test, describe } from 'vitest';
const cases = [1, 2, 3];
for (const case of cases) {
test(`case ${case} > first`, async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test(`case ${case} > second`, async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
} So it's solvable in user-land, but I still feel it's a "miss" from the test framework because |
Actually, I took a look of the current implementation and from my native thinking, it looks possible to run multiple vitest/packages/runner/src/run.ts Lines 312 to 316 in fee7d8b
but the semantics of Also, even if what I'm imagining is implemented, for describe.concurrentSuite("odd wrapper", () => {
describe.concurrent.each([1, 2])('case %i', () => {
test('first', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test('second', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
});
})
Yeah, regarding possible solution, your manual for loop should be totally fine. But, as you wrote on discord, vscode extension doesn't support it unfortunately. |
The tests are picked up if you only use So that's not that bad. 😄 Would something like this work? describe.concurrentSuite.concurrent.each([1, 2])('case %i', () => {
test('first', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
test('second', async () => {
await new Promise((resolve) => setTimeout(resolve, 10_000));
});
}); |
I don't know, it' just my preliminary tinkering, so I'm not even sure if it would actually work. |
So, after testing with jest, it seems like Here is a small repo showing the difference between Personally, |
It looks like Jest simply runs all I setup this example to investigate:
Though I don't think Jest is a good example to look up, I think Vitest's own way of suite level concurrency probably makes sense, so I'll continue on that on my PR. |
Describe the bug
It seems that
describe.concurrent.each
is implemented as a shortcut for setting{ concurrency: true }
in each describe block so the tests within it are run in concurrently.However, this is not how it works in Jest according to this PR: jestjs/jest#9326
describe.concurrent.each
should not alter the describe block options but execute each describe block concurrently.Here are my expectations:
Reproduction
I was not able to install
vitest
correctly in StackBlitz:But here is the link illustrating the issue: https://stackblitz.com/edit/vitest-dev-vitest-fwwzec?file=test%2Fbasic.test.ts
System Info
System: OS: macOS 14.4.1 CPU: (10) arm64 Apple M1 Pro Memory: 88.14 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.11.1 - /nix/store/xjgg53kjjhwcx4p3dmywjmqjbv82xhyn-nodejs-20.11.1/bin/node npm: 10.2.4 - /nix/store/xjgg53kjjhwcx4p3dmywjmqjbv82xhyn-nodejs-20.11.1/bin/npm pnpm: 8.15.5 - /nix/store/ih6qr7ga6i467b91kf52lkb6qhiib4s8-corepack-enable/bin/pnpm Browsers: Chrome: 123.0.6312.87 Safari: 17.4.1 npmPackages: vitest: 1.4.0 => 1.4.0
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: