Skip to content

Commit 71d0e40

Browse files
test(node-http-handler): add test for requestTimeout configuration
1 parent b8629ae commit 71d0e40

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

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

66
import { NodeHttpHandler } from "./node-http-handler";
77
import * as setConnectionTimeoutModule from "./set-connection-timeout";
8+
import * as setSocketTimeoutModule from "./set-socket-timeout";
89
import { timing } from "./timing";
910

1011
vi.mock("http", async () => {
@@ -56,6 +57,7 @@ describe("NodeHttpHandler", () => {
5657
const randomMaxSocket = Math.round(Math.random() * 50) + 1;
5758
const randomSocketAcquisitionWarningTimeout = Math.round(Math.random() * 10000) + 1;
5859
const randomConnectionTimeout = Math.round(Math.random() * 10000) + 1;
60+
const randomRequestTimeout = Math.round(Math.random() * 10000) + 1;
5961

6062
beforeEach(() => {});
6163

@@ -129,6 +131,21 @@ describe("NodeHttpHandler", () => {
129131
);
130132
});
131133

134+
it.each([
135+
["an options hash", { requestTimeout: randomRequestTimeout }],
136+
[
137+
"a provider",
138+
async () => ({
139+
requestTimeout: randomRequestTimeout,
140+
}),
141+
],
142+
])("sets requestTimeout correctly when input is %s", async (_, option) => {
143+
vi.spyOn(setSocketTimeoutModule, "setSocketTimeout");
144+
const nodeHttpHandler = new NodeHttpHandler(option);
145+
await nodeHttpHandler.handle({} as any);
146+
expect(vi.mocked(setSocketTimeoutModule.setSocketTimeout).mock.calls[0][2]).toBe(randomRequestTimeout);
147+
});
148+
132149
it.each([
133150
["an options hash", { httpAgent: new http.Agent({ keepAlive: false, maxSockets: randomMaxSocket }) }],
134151
[

0 commit comments

Comments
 (0)