

























@@ -106,32 +106,24 @@ describe("ensureGlobalUndiciStreamTimeouts", () => {
106106vi.mocked(resolveEnvHttpProxyAgentOptions).mockReturnValue(undefined);
107107});
108108109-it("replaces direct Agent dispatcher with extended stream timeouts when no env proxy is configured", () => {
109+it("records timeout bridge without importing undici when no env proxy is configured", () => {
110110getDefaultAutoSelectFamily.mockReturnValue(true);
111111112112ensureGlobalUndiciStreamTimeouts();
113113114-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-});
114+expect(loadUndiciGlobalDispatcherDeps).not.toHaveBeenCalled();
115+expect(setGlobalDispatcher).not.toHaveBeenCalled();
124116expect(undiciGlobalDispatcherModule._globalUndiciStreamTimeoutMs).toBe(
125117DEFAULT_UNDICI_STREAM_TIMEOUT_MS,
126118);
127119});
128120129-it("does not initialize the undici global dispatcher during no-proxy bootstrap", () => {
121+it("does not initialize the undici global dispatcher in a no-proxy subprocess", () => {
130122const moduleUrl = pathToFileURL(path.resolve("src/infra/net/undici-global-dispatcher.ts")).href;
131123const source = `
132124 const dispatcherKey = Symbol.for("undici.globalDispatcher.1");
133125 const mod = await import(${JSON.stringify(moduleUrl)});
134- mod.ensureGlobalUndiciEnvProxyDispatcher();
126+ mod.ensureGlobalUndiciStreamTimeouts({ timeoutMs: 1_900_000 });
135127 if (globalThis[dispatcherKey] !== undefined) {
136128 throw new Error("undici global dispatcher was initialized");
137129 }
@@ -222,12 +214,8 @@ describe("ensureGlobalUndiciStreamTimeouts", () => {
222214it("does not lower global stream timeouts below the default floor", () => {
223215ensureGlobalUndiciStreamTimeouts({ timeoutMs: 15_000 });
224216225-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);
217+expect(loadUndiciGlobalDispatcherDeps).not.toHaveBeenCalled();
218+expect(setGlobalDispatcher).not.toHaveBeenCalled();
231219expect(undiciGlobalDispatcherModule._globalUndiciStreamTimeoutMs).toBe(
232220DEFAULT_UNDICI_STREAM_TIMEOUT_MS,
233221);
@@ -238,12 +226,8 @@ describe("ensureGlobalUndiciStreamTimeouts", () => {
238226239227ensureGlobalUndiciStreamTimeouts({ timeoutMs });
240228241-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);
229+expect(loadUndiciGlobalDispatcherDeps).not.toHaveBeenCalled();
230+expect(setGlobalDispatcher).not.toHaveBeenCalled();
247231expect(undiciGlobalDispatcherModule._globalUndiciStreamTimeoutMs).toBe(timeoutMs);
248232});
249233此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。