mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 23:25:24 +00:00
25 lines
829 B
TypeScript
25 lines
829 B
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createPollQueue } from "../../src/frontend/poll-queue";
|
|
|
|
describe("background host polling queue", () => {
|
|
it("bounds concurrent hosts and releases a slot after failure", async () => {
|
|
const run = createPollQueue(2);
|
|
let release!: () => void;
|
|
const held = new Promise<void>((resolve) => {
|
|
release = resolve;
|
|
});
|
|
const first = run(() => held);
|
|
const second = run(async () => {
|
|
throw new Error("offline");
|
|
});
|
|
const thirdTask = vi.fn(async () => "third");
|
|
const third = run(thirdTask);
|
|
expect(thirdTask).not.toHaveBeenCalled();
|
|
await expect(second).rejects.toThrow("offline");
|
|
await expect(third).resolves.toBe("third");
|
|
expect(thirdTask).toHaveBeenCalledOnce();
|
|
release();
|
|
await first;
|
|
});
|
|
});
|