Menu
popagent
publicLatest change 6edc7e928c57dab23c0973ed3f7ee70b3ebb72d5 - Initial popagent baseline by AkurAI Build
import { describe, expect, test } from "bun:test";
import { retryableInit } from "./retryable-init";
describe("retryableInit", () => {
test("shares active initialization and retries after failure", async () => {
const release = Promise.withResolvers<void>();
let attempts = 0;
const init = retryableInit(async () => {
attempts++;
if (attempts === 1) throw new Error("database unavailable");
await release.promise;
});
await expect(init()).rejects.toThrow("database unavailable");
const retry = init();
expect(init()).toBe(retry);
expect(attempts).toBe(2);
release.resolve();
await retry;
expect(init()).toBe(retry);
expect(attempts).toBe(2);
});
});