mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:38:27 +00:00
perf(test): replace timeout ticks with microtask waits
This commit is contained in:
@@ -6,6 +6,10 @@ vi.mock("../infra/net/fetch-guard.js", () => ({
|
||||
fetchWithSsrFGuard: (...args: unknown[]) => fetchWithSsrFGuardMock(...args),
|
||||
}));
|
||||
|
||||
async function waitForMicrotaskTurn(): Promise<void> {
|
||||
await new Promise<void>((resolve) => queueMicrotask(resolve));
|
||||
}
|
||||
|
||||
describe("fetchWithGuard", () => {
|
||||
it("rejects oversized streamed payloads and cancels the stream", async () => {
|
||||
let canceled = false;
|
||||
@@ -47,7 +51,7 @@ describe("fetchWithGuard", () => {
|
||||
).rejects.toThrow("Content too large");
|
||||
|
||||
// Allow cancel() microtask to run.
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await waitForMicrotaskTurn();
|
||||
|
||||
expect(canceled).toBe(true);
|
||||
expect(release).toHaveBeenCalledTimes(1);
|
||||
|
||||
Reference in New Issue
Block a user