Skip to content

Commit

Permalink
Write some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minkimcello committed Dec 17, 2024
1 parent 1a5f5e2 commit 149e9d3
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions retry-backoff/retry-backoff.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { run } from "npm:[email protected]";
import { describe, it } from "bdd";
import { expect } from "expect";
import { useRetryWithBackoff } from "./retry-backoff.ts"

describe("RetryBackoff", () => {
it("retries operation and returns output if operation finishes on time", async () => {
await run(function* () {
let attempts = 0;
let result = 0;
yield* useRetryWithBackoff(function* () {
if (attempts < 2) {
attempts++;
throw new Error("operation failed");
} else {
result = 1;
}
}, { timeout: 2_000 });
expect(attempts).toBe(2);
expect(result).toBe(1);
})
});

it("retries operation and handles timeout when operation exceeds limit", async () => {
await run(function* () {
let attempts = 0;
let result = 0;
yield* useRetryWithBackoff(function* () {
if (attempts < 2) {
attempts++;
throw new Error("operation failed");
} else {
result = 1;
}
}, { timeout: 500 });
expect(result).toBe(0);
})
});
});

0 comments on commit 149e9d3

Please sign in to comment.