Replies: 2 comments 5 replies
-
The recommended approach is to limit concurrency (e.g. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Using // package.json
"ava": {
"environmentVariables": {
"concurrency": "10"
}
} // test.ts
import anyTest, { type TestFn } from "ava";
import { Semaphore, type Permit } from "@shopify/semaphore";
const test = anyTest as TestFn<{
permit: Permit;
}>;
const semaphore = new Semaphore(Number(process.env.concurrency) || 5);
test.beforeEach("setup concurrency", async t => {
t.context.permit = await semaphore.acquire();
});
test.afterEach.always(async t => {
await t.context.permit.release();
});
// ... |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am running tests that perform relatively heavy weight tasks like rendering pages in headless chrome. My tests also need to complete within a certain time window or they are considered failed. With the standard ava execution strategy, test files are run in parallel and all asynchronous tests within each test file are executed concurrently. So when ava is started it's like a massive stampede of tests that hits the machine. This causes tests to run much slower than they otherwise would.
I have a proposal for two new features that would help a lot in this situation:
1) Serial test files
Ava has the feature to mark individual test cases as
serial
, which causes them to be run serially before all other test cases. This new proposed feature would work the same way but for test files instead, causing them to be run serially before all other test files.My current ugly workaround is to run multiple instances of ava:
2) Limit concurrent async tasks per test file
Ava executes all asynchronous test cases within a single test file concurrently. So if I have 100 test cases in a file and each test case opens a tab in headless chrome, then I have 100 tabs open which puts a lot of strain on the system. The new proposed feature would limit the number of test cases that are executed concurrently per test file.
My current workaround is to use a custom semaphore implementation to throttle test cases:
It's not pretty but workable.
I would like to know from you if you think these features would be worth adding to ava.
Beta Was this translation helpful? Give feedback.
All reactions