Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

test(request): close the test server in a finally and bound the request

Vlad Ligaiac7dfad57c3c
diff --git a/backend/src/lib/config/request.test.ts b/backend/src/lib/config/request.test.ts
index 136b3e84c3..6d66d57523 100644
--- a/backend/src/lib/config/request.test.ts
+++ b/backend/src/lib/config/request.test.ts
@@ -42,10 +42,17 @@ describe("createRequestClient", () => {
await new Promise<void>((resolve) => {
server.listen(0, "127.0.0.1", resolve);
});
- const { port } = server.address() as AddressInfo;
- const err = (await client.get(`http://127.0.0.1:${port}/`).catch((e: unknown) => e)) as AxiosError;
- server.close();
- expect(err.message).toBe("Request failed with status code 500");
- expect(err.response?.status).toBe(500);
+ try {
+ const { port } = server.address() as AddressInfo;
+ const err = (await client
+ .get(`http://127.0.0.1:${port}/`, { timeout: 5000 })
+ .catch((e: unknown) => e)) as AxiosError;
+ expect(err.message).toBe("Request failed with status code 500");
+ expect(err.response?.status).toBe(500);
+ } finally {
+ await new Promise<void>((resolve) => {
+ server.close(() => resolve());
+ });
+ }
});
});