mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 21:57:26 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -3,6 +3,10 @@ import { runTasksWithConcurrency } from "./run-with-concurrency.js";
|
||||
|
||||
describe("runTasksWithConcurrency", () => {
|
||||
it("preserves task order with bounded worker count", async () => {
|
||||
const flushMicrotasks = async () => {
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
};
|
||||
let running = 0;
|
||||
let peak = 0;
|
||||
const resolvers: Array<(() => void) | undefined> = [];
|
||||
@@ -17,18 +21,18 @@ describe("runTasksWithConcurrency", () => {
|
||||
});
|
||||
|
||||
const resultPromise = runTasksWithConcurrency({ tasks, limit: 2 });
|
||||
await vi.waitFor(() => {
|
||||
expect(typeof resolvers[0]).toBe("function");
|
||||
expect(typeof resolvers[1]).toBe("function");
|
||||
});
|
||||
await flushMicrotasks();
|
||||
expect(typeof resolvers[0]).toBe("function");
|
||||
expect(typeof resolvers[1]).toBe("function");
|
||||
|
||||
resolvers[1]?.();
|
||||
await vi.waitFor(() => {
|
||||
expect(typeof resolvers[2]).toBe("function");
|
||||
});
|
||||
await flushMicrotasks();
|
||||
expect(typeof resolvers[2]).toBe("function");
|
||||
|
||||
resolvers[0]?.();
|
||||
await vi.waitFor(() => {
|
||||
expect(typeof resolvers[3]).toBe("function");
|
||||
});
|
||||
await flushMicrotasks();
|
||||
expect(typeof resolvers[3]).toBe("function");
|
||||
|
||||
resolvers[2]?.();
|
||||
resolvers[3]?.();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user