Spaces:
Sleeping
Sleeping
Download apps/server/src/outbox/runtime.unit.test.ts from phucsd/Oloka-Video-Dev: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/phucsd/Oloka-Video-Dev/resolve/main/apps/server/src/outbox/runtime.unit.test.ts
- Command line
-
hf download hf://spaces/phucsd/Oloka-Video-Dev/apps/server/src/outbox/runtime.unit.test.ts
-
curl -L -o runtime.unit.test.ts https://huggingface.co/spaces/phucsd/Oloka-Video-Dev/resolve/main/apps/server/src/outbox/runtime.unit.test.ts
1.09 kB
| import { describe, expect, it, vi } from "vitest"; | |
| import type { OutboxConsumer } from "./consumer.js"; | |
| import { OutboxRuntime } from "./runtime.js"; | |
| describe("OutboxRuntime", () => { | |
| it("does not overlap concurrent startup passes", async () => { | |
| let release: (() => void) | undefined; | |
| let active = 0; | |
| let maximumActive = 0; | |
| const runOnce = vi.fn(async () => { | |
| active += 1; | |
| maximumActive = Math.max(maximumActive, active); | |
| await new Promise<void>((resolve) => { | |
| release = resolve; | |
| }); | |
| active -= 1; | |
| return 0; | |
| }); | |
| const consumer = { | |
| runOnce, | |
| shutdown: vi.fn(), | |
| } as unknown as OutboxConsumer; | |
| const runtime = new OutboxRuntime(consumer, { pollIntervalMs: 1_000 }); | |
| const firstStart = runtime.start(); | |
| const secondStart = runtime.start(); | |
| await vi.waitFor(() => expect(runOnce).toHaveBeenCalled()); | |
| expect(runOnce).toHaveBeenCalledTimes(1); | |
| expect(maximumActive).toBe(1); | |
| release?.(); | |
| await Promise.all([firstStart, secondStart]); | |
| await runtime.stop(); | |
| }); | |
| }); | |