Skip to content

Commit 30c18e8

Browse files
committed
test(infra): stabilize CONNECT timeout cap test
1 parent 9a89cc6 commit 30c18e8

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/infra/net/http-connect-tunnel.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ describe("openHttpConnectTunnel", () => {
353353

354354
it("caps oversized CONNECT timeouts before arming the watchdog", async () => {
355355
vi.useFakeTimers();
356+
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
356357
const proxySocket = new FakeSocket();
357358
setNextNetSocket(proxySocket);
358359
const { openHttpConnectTunnel } = await import("./http-connect-tunnel.js");
@@ -363,14 +364,16 @@ describe("openHttpConnectTunnel", () => {
363364
targetPort: 443,
364365
timeoutMs: Number.MAX_SAFE_INTEGER,
365366
});
367+
const rejected = expect(tunnel).rejects.toThrow(
368+
`Proxy CONNECT failed via http://proxy.example:8080: Proxy CONNECT timed out after ${MAX_TIMER_TIMEOUT_MS}ms`,
369+
);
370+
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
366371

367372
await vi.advanceTimersByTimeAsync(1);
368373
expect(proxySocket.destroyed).toBe(false);
369374

370-
await vi.advanceTimersByTimeAsync(MAX_TIMER_TIMEOUT_MS - 1);
371-
await expect(tunnel).rejects.toThrow(
372-
`Proxy CONNECT failed via http://proxy.example:8080: Proxy CONNECT timed out after ${MAX_TIMER_TIMEOUT_MS}ms`,
373-
);
375+
await vi.advanceTimersToNextTimerAsync();
376+
await rejected;
374377
expect(proxySocket.destroyed).toBe(true);
375378
});
376379
});

0 commit comments

Comments
 (0)