summaryrefslogtreecommitdiff
path: root/cli/tests/unit/http_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-09-26 19:46:06 +0900
committerGitHub <noreply@github.com>2023-09-26 19:46:06 +0900
commitc68650d53244ab5cc3cda232085a63cbb497f83b (patch)
tree5e537af29d8df0ac1a4b07e7fdf7fc5f524fd232 /cli/tests/unit/http_test.ts
parent6f87962a77f3dd409c71ff490fd5f36023b7b700 (diff)
fix(cli/test): clear connection pool after tests (#20680)
This helps reduce flakes where a test starts an HTTP server and makes a request using fetch, then shuts down the server, then starting a new test with a new server, but the connection pool still has a "not quite closed yet" connection to the old server, and a new request to the new server gets sent on the closed connection, which obviously errors out.
Diffstat (limited to 'cli/tests/unit/http_test.ts')
-rw-r--r--cli/tests/unit/http_test.ts16
1 files changed, 3 insertions, 13 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 4fef626d6..10414cab3 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -198,14 +198,12 @@ Deno.test(
await respondWith(new Response(stream.readable));
})();
- const client = Deno.createHttpClient({});
- const resp = await fetch(`http://127.0.0.1:${listenPort}/`, { client });
+ const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
const respBody = await resp.text();
assertEquals("hello world", respBody);
await promise;
httpConn!.close();
listener.close();
- client.close();
},
);
@@ -237,17 +235,14 @@ Deno.test(
listener.close();
})();
- const client = Deno.createHttpClient({});
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
body: stream.readable,
method: "POST",
headers: { "connection": "close" },
- client,
});
await resp.arrayBuffer();
await promise;
- client.close();
},
);
@@ -354,13 +349,13 @@ Deno.test(
const caCert = Deno.readTextFileSync("cli/tests/testdata/tls/RootCA.pem");
const client = Deno.createHttpClient({ caCerts: [caCert] });
const resp = await fetch(`https://${hostname}:${port}/`, {
- client,
headers: { "connection": "close" },
+ client,
});
+ client.close();
const respBody = await resp.text();
assertEquals("Hello World", respBody);
await promise;
- client.close();
},
);
@@ -380,11 +375,9 @@ Deno.test(
await respondWith(new Response("response"));
})();
- const client = Deno.createHttpClient({});
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
method: "POST",
body: "request",
- client,
});
const respBody = await resp.text();
assertEquals("response", respBody);
@@ -392,7 +385,6 @@ Deno.test(
httpConn!.close();
listener.close();
- client.close();
},
);
@@ -435,11 +427,9 @@ Deno.test(
listener.close();
})();
- const client = Deno.createHttpClient({});
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
await resp.body!.cancel();
await promise;
- client.close();
},
);