Skip to content

Commit aae226d

Browse files
test(node-http-handler): add test for socketAcquisitionWarningTimeout (#1598)
* test(node-http-handler): add test for socketAcquisitionWarningTimeout * test(node-http-handler): modify test * chore: add empty changeset.
1 parent 2dfa84a commit aae226d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.changeset/red-dryers-dress.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

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

Lines changed: 17 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 { timing } from "./timing";
78

89
vi.mock("http", async () => {
910
const actual = (await vi.importActual("http")) as any;
@@ -52,6 +53,7 @@ import { request as hsRequest } from "https";
5253
describe("NodeHttpHandler", () => {
5354
describe("constructor and #handle", () => {
5455
const randomMaxSocket = Math.round(Math.random() * 50) + 1;
56+
const randomSocketAcquisitionWarningTimeout = Math.round(Math.random() * 10000) + 1;
5557

5658
beforeEach(() => {});
5759

@@ -93,6 +95,21 @@ describe("NodeHttpHandler", () => {
9395
expect(vi.mocked(hRequest as any).mock.calls[0][0]?.agent.maxSockets).toEqual(50);
9496
});
9597

98+
it.each([
99+
["an options hash", { socketAcquisitionWarningTimeout: randomSocketAcquisitionWarningTimeout }],
100+
[
101+
"a provider",
102+
async () => ({
103+
socketAcquisitionWarningTimeout: randomSocketAcquisitionWarningTimeout,
104+
}),
105+
],
106+
])("sets socketAcquisitionWarningTimeout correctly when input is %s", async (_, option) => {
107+
vi.spyOn(timing, "setTimeout");
108+
const nodeHttpHandler = new NodeHttpHandler(option);
109+
await nodeHttpHandler.handle({} as any);
110+
expect(vi.mocked(timing.setTimeout).mock.calls[0][1]).toBe(randomSocketAcquisitionWarningTimeout);
111+
});
112+
96113
it.each([
97114
["an options hash", { httpAgent: new http.Agent({ keepAlive: false, maxSockets: randomMaxSocket }) }],
98115
[

0 commit comments

Comments
 (0)