-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a5f5e2
commit 149e9d3
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}); | ||
}); |