Skip to content

Commit

Permalink
test(async/unstable): add retry() tests (#6423)
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen authored Feb 19, 2025
1 parent e9888ea commit b6e6bf0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions async/unstable_retry_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ import { assertEquals, assertRejects } from "@std/assert";
import { retry } from "./unstable_retry.ts";
import { RetryError } from "./retry.ts";

Deno.test("retry() throws if maxTimeout is negative", async () => {
await assertRejects(
async () => await retry(() => {}, { maxTimeout: -1 }),
TypeError,
"Cannot retry as 'maxTimeout' must be positive: current value is -1",
);
});

Deno.test("retry() throws if minTimeout is bigger than maxTimeout", async () => {
await assertRejects(
async () => await retry(() => {}, { maxTimeout: 1, minTimeout: 2 }),
TypeError,
"Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=2', 'maxTimeout=1'",
);
});

Deno.test("retry() throws if jitter is bigger than 1", async () => {
await assertRejects(
async () => await retry(() => {}, { jitter: 2 }),
TypeError,
"Cannot retry as 'jitter' must be <= 1: current value is 2",
);
});

Deno.test("retry() only retries errors that are retriable with `isRetriable` option", async () => {
class HttpError extends Error {
status: number;
Expand Down

0 comments on commit b6e6bf0

Please sign in to comment.