mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 07:02:44 +00:00
Telegram: harden network retries and config
Co-authored-by: techboss <techboss@users.noreply.github.com>
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
e43f4c0628
commit
b861a0bd73
27
src/infra/retry-policy.test.ts
Normal file
27
src/infra/retry-policy.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTelegramRetryRunner } from "./retry-policy.js";
|
||||
|
||||
describe("createTelegramRetryRunner", () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("retries when custom shouldRetry matches non-telegram error", async () => {
|
||||
vi.useFakeTimers();
|
||||
const runner = createTelegramRetryRunner({
|
||||
retry: { attempts: 2, minDelayMs: 0, maxDelayMs: 0, jitter: 0 },
|
||||
shouldRetry: (err) => err instanceof Error && err.message === "boom",
|
||||
});
|
||||
const fn = vi
|
||||
.fn<[], Promise<string>>()
|
||||
.mockRejectedValueOnce(new Error("boom"))
|
||||
.mockResolvedValue("ok");
|
||||
|
||||
const promise = runner(fn, "request");
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
await expect(promise).resolves.toBe("ok");
|
||||
expect(fn).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user