chore: further redis cleanup

This commit is contained in:
Charlie Lamb
2026-04-20 14:21:59 +01:00
parent dcd2be574e
commit 7f69e93176
8 changed files with 151 additions and 97 deletions

View File

@@ -0,0 +1,29 @@
import { describe, expect, test } from "bun:test";
import { withTimeout } from "@/utils/withTimeout.js";
describe("withTimeout", () => {
test("returns the wrapped result before the timeout", async () => {
const result = await withTimeout({
timeoutMs: 50,
fn: async () => "ok",
});
expect(result).toBe("ok");
});
test("rejects and runs onTimeout when the timeout elapses", async () => {
let timedOut = false;
await expect(
withTimeout({
timeoutMs: 10,
fn: () => new Promise<string>(() => {}),
onTimeout: () => {
timedOut = true;
},
}),
).rejects.toThrow("timed out after 10ms");
expect(timedOut).toBe(true);
});
});