
























@@ -106,24 +106,32 @@ describe("ensureGlobalUndiciStreamTimeouts", () => {
106106vi.mocked(resolveEnvHttpProxyAgentOptions).mockReturnValue(undefined);
107107});
108108109-it("records timeout bridge without importing undici when no env proxy is configured", () => {
109+it("replaces direct Agent dispatcher with extended stream timeouts when no env proxy is configured", () => {
110110getDefaultAutoSelectFamily.mockReturnValue(true);
111111112112ensureGlobalUndiciStreamTimeouts();
113113114-expect(loadUndiciGlobalDispatcherDeps).not.toHaveBeenCalled();
115-expect(setGlobalDispatcher).not.toHaveBeenCalled();
114+expect(loadUndiciGlobalDispatcherDeps).toHaveBeenCalledTimes(1);
115+expect(setGlobalDispatcher).toHaveBeenCalledTimes(1);
116+const next = getCurrentDispatcher() as { options?: Record<string, unknown> };
117+expect(next).toBeInstanceOf(Agent);
118+expect(next.options?.bodyTimeout).toBe(DEFAULT_UNDICI_STREAM_TIMEOUT_MS);
119+expect(next.options?.headersTimeout).toBe(DEFAULT_UNDICI_STREAM_TIMEOUT_MS);
120+expect(next.options?.connect).toEqual({
121+autoSelectFamily: true,
122+autoSelectFamilyAttemptTimeout: 300,
123+});
116124expect(undiciGlobalDispatcherModule._globalUndiciStreamTimeoutMs).toBe(
117125DEFAULT_UNDICI_STREAM_TIMEOUT_MS,
118126);
119127});
120128121-it("does not initialize the undici global dispatcher in a no-proxy subprocess", () => {
129+it("does not initialize the undici global dispatcher during no-proxy bootstrap", () => {
122130const moduleUrl = pathToFileURL(path.resolve("src/infra/net/undici-global-dispatcher.ts")).href;
123131const source = `
124132 const dispatcherKey = Symbol.for("undici.globalDispatcher.1");
125133 const mod = await import(${JSON.stringify(moduleUrl)});
126- mod.ensureGlobalUndiciStreamTimeouts({ timeoutMs: 1_900_000 });
134+ mod.ensureGlobalUndiciEnvProxyDispatcher();
127135 if (globalThis[dispatcherKey] !== undefined) {
128136 throw new Error("undici global dispatcher was initialized");
129137 }
@@ -214,8 +222,12 @@ describe("ensureGlobalUndiciStreamTimeouts", () => {
214222it("does not lower global stream timeouts below the default floor", () => {
215223ensureGlobalUndiciStreamTimeouts({ timeoutMs: 15_000 });
216224217-expect(loadUndiciGlobalDispatcherDeps).not.toHaveBeenCalled();
218-expect(setGlobalDispatcher).not.toHaveBeenCalled();
225+expect(loadUndiciGlobalDispatcherDeps).toHaveBeenCalledTimes(1);
226+expect(setGlobalDispatcher).toHaveBeenCalledTimes(1);
227+const next = getCurrentDispatcher() as { options?: Record<string, unknown> };
228+expect(next).toBeInstanceOf(Agent);
229+expect(next.options?.bodyTimeout).toBe(DEFAULT_UNDICI_STREAM_TIMEOUT_MS);
230+expect(next.options?.headersTimeout).toBe(DEFAULT_UNDICI_STREAM_TIMEOUT_MS);
219231expect(undiciGlobalDispatcherModule._globalUndiciStreamTimeoutMs).toBe(
220232DEFAULT_UNDICI_STREAM_TIMEOUT_MS,
221233);
@@ -226,8 +238,12 @@ describe("ensureGlobalUndiciStreamTimeouts", () => {
226238227239ensureGlobalUndiciStreamTimeouts({ timeoutMs });
228240229-expect(loadUndiciGlobalDispatcherDeps).not.toHaveBeenCalled();
230-expect(setGlobalDispatcher).not.toHaveBeenCalled();
241+expect(loadUndiciGlobalDispatcherDeps).toHaveBeenCalledTimes(1);
242+expect(setGlobalDispatcher).toHaveBeenCalledTimes(1);
243+const next = getCurrentDispatcher() as { options?: Record<string, unknown> };
244+expect(next).toBeInstanceOf(Agent);
245+expect(next.options?.bodyTimeout).toBe(timeoutMs);
246+expect(next.options?.headersTimeout).toBe(timeoutMs);
231247expect(undiciGlobalDispatcherModule._globalUndiciStreamTimeoutMs).toBe(timeoutMs);
232248});
233249此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。