You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

import { afterEach, describe, expect, it, vi } from "vitest";
import {
resetListHttpGateForTests,
runWithListHttpGate,
} from "@/services/cc/list-http-gate";
describe("runWithListHttpGate", () => {
afterEach(() => {
vi.useRealTimers();
resetListHttpGateForTests();
});
it("waits 60s between HTTP slots for the same profile", async () => {
vi.useFakeTimers();
const calls: number[] = [];
const first = runWithListHttpGate("profile:1", async () => {
calls.push(Date.now());
return "a";
});
await vi.runOnlyPendingTimersAsync();
await first;
const second = runWithListHttpGate("profile:1", async () => {
calls.push(Date.now());
return "b";
});
await vi.advanceTimersByTimeAsync(59_000);
let settled = false;
void second.then(() => {
settled = true;
});
await Promise.resolve();
expect(settled).toBe(false);
await vi.advanceTimersByTimeAsync(1_000);
expect(await second).toBe("b");
expect(calls).toHaveLength(2);
});
});