1import { assert, it } from "@effect/vitest";
2
3import { retryShowcaseOperation } from "./showcaseRetry";
4
5it("retries a failed showcase operation until it succeeds", async () => {
6 let attempts = 0;
7 const succeeded = await retryShowcaseOperation(
8 async () => {
9 attempts += 1;
10 return attempts === 3;
11 },
12 { isCancelled: () => false, retryDelayMs: 0 },
13 );
14
15 assert.equal(succeeded, true);
16 assert.equal(attempts, 3);
17});
18
19it("recovers when a showcase operation attempt hangs", async () => {
20 let attempts = 0;
21 const succeeded = await retryShowcaseOperation(
22 () => {
23 attempts += 1;
24 return attempts === 1 ? new Promise<boolean>(() => undefined) : Promise.resolve(true);
25 },
26 { isCancelled: () => false, attemptTimeoutMs: 1, retryDelayMs: 0 },
27 );
28
29 assert.equal(succeeded, true);
30 assert.equal(attempts, 2);
31});
32
33it("stops retrying when the owning showcase effect is cancelled", async () => {
34 let cancelled = false;
35 const succeeded = await retryShowcaseOperation(
36 async () => {
37 cancelled = true;
38 return false;
39 },
40 { isCancelled: () => cancelled, retryDelayMs: 0 },
41 );
42
43 assert.equal(succeeded, false);
44});