Skip to content

Commit b8629ae

Browse files
test(node-http-handler): add test for connectionTimeout configuration
1 parent 9f58ff3 commit b8629ae

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import https from "https";
44
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
55

66
import { NodeHttpHandler } from "./node-http-handler";
7+
import * as setConnectionTimeoutModule from "./set-connection-timeout";
78
import { timing } from "./timing";
89

910
vi.mock("http", async () => {
@@ -54,6 +55,7 @@ describe("NodeHttpHandler", () => {
5455
describe("constructor and #handle", () => {
5556
const randomMaxSocket = Math.round(Math.random() * 50) + 1;
5657
const randomSocketAcquisitionWarningTimeout = Math.round(Math.random() * 10000) + 1;
58+
const randomConnectionTimeout = Math.round(Math.random() * 10000) + 1;
5759

5860
beforeEach(() => {});
5961

@@ -110,6 +112,23 @@ describe("NodeHttpHandler", () => {
110112
expect(vi.mocked(timing.setTimeout).mock.calls[0][1]).toBe(randomSocketAcquisitionWarningTimeout);
111113
});
112114

115+
it.each([
116+
["an options hash", { connectionTimeout: randomConnectionTimeout }],
117+
[
118+
"a provider",
119+
async () => ({
120+
connectionTimeout: randomConnectionTimeout,
121+
}),
122+
],
123+
])("sets connectionTimeout correctly when input is %s", async (_, option) => {
124+
vi.spyOn(setConnectionTimeoutModule, "setConnectionTimeout");
125+
const nodeHttpHandler = new NodeHttpHandler(option);
126+
await nodeHttpHandler.handle({} as any);
127+
expect(vi.mocked(setConnectionTimeoutModule.setConnectionTimeout).mock.calls[0][2]).toBe(
128+
randomConnectionTimeout
129+
);
130+
});
131+
113132
it.each([
114133
["an options hash", { httpAgent: new http.Agent({ keepAlive: false, maxSockets: randomMaxSocket }) }],
115134
[

0 commit comments

Comments
 (0)