perf(test): remove timer sleeps from concurrency test
This commit is contained in:
parent
e9b4d86e37
commit
5d81c3ead6
@ -5,15 +5,34 @@ describe("runTasksWithConcurrency", () => {
|
|||||||
it("preserves task order with bounded worker count", async () => {
|
it("preserves task order with bounded worker count", async () => {
|
||||||
let running = 0;
|
let running = 0;
|
||||||
let peak = 0;
|
let peak = 0;
|
||||||
const tasks = [25, 10, 5, 15].map((delayMs, index) => async (): Promise<number> => {
|
const resolvers: Array<(() => void) | undefined> = [];
|
||||||
|
const tasks = [0, 1, 2, 3].map((index) => async (): Promise<number> => {
|
||||||
running += 1;
|
running += 1;
|
||||||
peak = Math.max(peak, running);
|
peak = Math.max(peak, running);
|
||||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
await new Promise<void>((resolve) => {
|
||||||
|
resolvers[index] = resolve;
|
||||||
|
});
|
||||||
running -= 1;
|
running -= 1;
|
||||||
return index + 1;
|
return index + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await runTasksWithConcurrency({ tasks, limit: 2 });
|
const resultPromise = runTasksWithConcurrency({ tasks, limit: 2 });
|
||||||
|
await vi.waitFor(() => {
|
||||||
|
expect(typeof resolvers[0]).toBe("function");
|
||||||
|
expect(typeof resolvers[1]).toBe("function");
|
||||||
|
});
|
||||||
|
resolvers[1]?.();
|
||||||
|
await vi.waitFor(() => {
|
||||||
|
expect(typeof resolvers[2]).toBe("function");
|
||||||
|
});
|
||||||
|
resolvers[0]?.();
|
||||||
|
await vi.waitFor(() => {
|
||||||
|
expect(typeof resolvers[3]).toBe("function");
|
||||||
|
});
|
||||||
|
resolvers[2]?.();
|
||||||
|
resolvers[3]?.();
|
||||||
|
|
||||||
|
const result = await resultPromise;
|
||||||
expect(result.hasError).toBe(false);
|
expect(result.hasError).toBe(false);
|
||||||
expect(result.firstError).toBeUndefined();
|
expect(result.firstError).toBeUndefined();
|
||||||
expect(result.results).toEqual([1, 2, 3, 4]);
|
expect(result.results).toEqual([1, 2, 3, 4]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user