
























@@ -1,4 +1,5 @@
11import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+import { resolveTimerTimeoutMs } from "../shared/number-coercion.js";
23import { MAX_SAFE_TIMEOUT_DELAY_MS } from "../utils/timer-delay.js";
34import { resolveRetryConfig, retryAsync } from "./retry.js";
45@@ -205,11 +206,12 @@ describe("retryAsync", () => {
205206vi.useFakeTimers();
206207const timeoutSpy = vi.spyOn(globalThis, "setTimeout");
207208const fn = vi.fn().mockRejectedValueOnce(new Error("boom")).mockResolvedValueOnce("ok");
209+const scheduledDelayMs = resolveTimerTimeoutMs(MAX_SAFE_TIMEOUT_DELAY_MS, 0, 0);
208210try {
209211const promise = retryAsync(fn, 2, 3_000_000_000);
210212await vi.advanceTimersByTimeAsync(MAX_SAFE_TIMEOUT_DELAY_MS);
211213await expect(promise).resolves.toBe("ok");
212-expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_SAFE_TIMEOUT_DELAY_MS);
214+expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), scheduledDelayMs);
213215} finally {
214216timeoutSpy.mockRestore();
215217vi.clearAllTimers();
@@ -226,21 +228,14 @@ describe("retryAsync", () => {
226228.mockRejectedValueOnce(new Error("boom-1"))
227229.mockRejectedValueOnce(new Error("boom-2"))
228230.mockResolvedValueOnce("ok");
231+const scheduledDelayMs = resolveTimerTimeoutMs(MAX_SAFE_TIMEOUT_DELAY_MS, 0, 0);
229232try {
230233const promise = retryAsync(fn, 3, Number.MAX_VALUE);
231234await vi.advanceTimersByTimeAsync(MAX_SAFE_TIMEOUT_DELAY_MS);
232235await vi.advanceTimersByTimeAsync(MAX_SAFE_TIMEOUT_DELAY_MS);
233236await expect(promise).resolves.toBe("ok");
234-expect(timeoutSpy).toHaveBeenNthCalledWith(
235-1,
236-expect.any(Function),
237-MAX_SAFE_TIMEOUT_DELAY_MS,
238-);
239-expect(timeoutSpy).toHaveBeenNthCalledWith(
240-2,
241-expect.any(Function),
242-MAX_SAFE_TIMEOUT_DELAY_MS,
243-);
237+expect(timeoutSpy).toHaveBeenNthCalledWith(1, expect.any(Function), scheduledDelayMs);
238+expect(timeoutSpy).toHaveBeenNthCalledWith(2, expect.any(Function), scheduledDelayMs);
244239} finally {
245240timeoutSpy.mockRestore();
246241vi.clearAllTimers();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。