Skip to content

Commit 46684e8

Browse files
committed
test: cover executeRun retry exhaustion
1 parent 39e39a0 commit 46684e8

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.changeset/long-comics-doubt.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

src/lib/executors/__tests__/run.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { describe, expect, it } from "bun:test"
22
import type { TryCtx } from "../../types/core"
3-
import { CancellationError, Panic, TimeoutError, UnhandledException } from "../../errors"
3+
import {
4+
CancellationError,
5+
Panic,
6+
RetryExhaustedError,
7+
TimeoutError,
8+
UnhandledException,
9+
} from "../../errors"
410
import { sleep } from "../../utils"
511
import { executeRun } from "../run"
612

@@ -64,6 +70,39 @@ describe("executeRun", () => {
6470
expect((error as Panic).code).toBe("RUN_CATCH_HANDLER_REJECT")
6571
}
6672
})
73+
74+
it("returns RetryExhaustedError and skips catch when retries are exhausted", async () => {
75+
let attempts = 0
76+
let mapped = false
77+
const cause = new Error("boom")
78+
79+
const result = (await executeRun(
80+
{
81+
retry: { backoff: "constant", delayMs: 0, limit: 2 },
82+
},
83+
{
84+
catch: () => {
85+
mapped = true
86+
return "mapped"
87+
},
88+
try: async () => {
89+
await Promise.resolve()
90+
attempts += 1
91+
throw cause
92+
},
93+
}
94+
)) as unknown as object
95+
96+
expect(result).toBeInstanceOf(RetryExhaustedError)
97+
98+
if (!(result instanceof RetryExhaustedError)) {
99+
expect.unreachable("should return RetryExhaustedError")
100+
}
101+
102+
expect(result.cause).toBe(cause)
103+
expect(attempts).toBe(2)
104+
expect(mapped).toBe(false)
105+
})
67106
})
68107

69108
describe("timeout behavior", () => {

0 commit comments

Comments
 (0)