


























11import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22import { createMattermostClient, createMattermostDirectChannelWithRetry } from "./client.js";
334+const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
5+46describe("createMattermostDirectChannelWithRetry", () => {
57const mockFetch = vi.fn<typeof fetch>();
68@@ -350,6 +352,28 @@ describe("createMattermostDirectChannelWithRetry", () => {
350352expect(abortListenerCalled).toBe(true);
351353});
352354355+it("caps oversized request timeouts before scheduling aborts", async () => {
356+const timeoutSpy = vi
357+.spyOn(globalThis, "setTimeout")
358+.mockImplementation((() => 1) as typeof setTimeout);
359+vi.spyOn(globalThis, "clearTimeout").mockImplementation(() => undefined);
360+mockFetch.mockResolvedValueOnce({
361+ok: true,
362+status: 201,
363+headers: new Headers({ "content-type": "application/json" }),
364+json: async () => ({ id: "dm-channel-capped" }),
365+} as Response);
366+367+const client = createMockClient();
368+369+await createMattermostDirectChannelWithRetry(client, ["user-1", "user-2"], {
370+timeoutMs: MAX_TIMER_TIMEOUT_MS + 1_000_000,
371+maxRetries: 0,
372+});
373+374+expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
375+});
376+353377it("uses exponential backoff with jitter between retries", async () => {
354378const delays: number[] = [];
355379mockFetch
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。