diff options
author | Luca Casonato <hello@lcas.dev> | 2023-09-26 19:46:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-26 19:46:06 +0900 |
commit | c68650d53244ab5cc3cda232085a63cbb497f83b (patch) | |
tree | 5e537af29d8df0ac1a4b07e7fdf7fc5f524fd232 /cli/tests/unit/serve_test.ts | |
parent | 6f87962a77f3dd409c71ff490fd5f36023b7b700 (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/serve_test.ts')
-rw-r--r-- | cli/tests/unit/serve_test.ts | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts index b2b05d00c..193b04ed1 100644 --- a/cli/tests/unit/serve_test.ts +++ b/cli/tests/unit/serve_test.ts @@ -965,8 +965,7 @@ function createStreamTest(count: number, delay: number, action: string) { try { await listeningPromise; - const client = Deno.createHttpClient({}); - const resp = await fetch(`http://127.0.0.1:${servePort}/`, { client }); + const resp = await fetch(`http://127.0.0.1:${servePort}/`); if (action == "Throw") { await assertRejects(async () => { await resp.text(); @@ -981,7 +980,6 @@ function createStreamTest(count: number, delay: number, action: string) { assertEquals(text, expected); } - client.close(); } finally { ac.abort(); await server.shutdown(); @@ -1098,14 +1096,12 @@ Deno.test( }); await listeningPromise; - const client = Deno.createHttpClient({}); - const resp = await fetch(`http://127.0.0.1:${servePort}/`, { client }); + const resp = await fetch(`http://127.0.0.1:${servePort}/`); const respBody = await resp.text(); assertEquals("", respBody); ac.abort(); await server.finished; - client.close(); }, ); @@ -1142,14 +1138,12 @@ Deno.test( }); await listeningPromise; - const client = Deno.createHttpClient({}); - const resp = await fetch(`http://127.0.0.1:${servePort}/`, { client }); + const resp = await fetch(`http://127.0.0.1:${servePort}/`); // Incorrectly implemented reader ReadableStream should reject. assertStringIncludes(await resp.text(), "Failed to execute 'enqueue'"); await errorPromise; ac.abort(); await server.finished; - client.close(); }, ); @@ -1606,11 +1600,9 @@ Deno.test( ); const { readable, writable } = new TransformStream(); - const client = Deno.createHttpClient({}); const resp = await fetch(`http://127.0.0.1:${servePort}/`, { method: "POST", body: readable, - client, }); await promise; @@ -1618,7 +1610,6 @@ Deno.test( await testDuplex(resp.body.getReader(), writable.getWriter()); ac.abort(); await server.finished; - client.close(); }, ); @@ -1653,11 +1644,9 @@ Deno.test( ); const { readable, writable } = new TransformStream(); - const client = Deno.createHttpClient({}); const resp = await fetch(`http://127.0.0.1:${servePort}/`, { method: "POST", body: readable, - client, }); await promise; @@ -1665,7 +1654,6 @@ Deno.test( await testDuplex(resp.body.getReader(), writable.getWriter()); ac.abort(); await server.finished; - client.close(); }, ); @@ -2624,12 +2612,9 @@ for (const testCase of compressionTestCases) { }); try { await listeningPromise; - const client = Deno.createHttpClient({}); const resp = await fetch(`http://127.0.0.1:${servePort}/`, { headers: testCase.in as HeadersInit, - client, }); - client.close(); await promise; const body = await resp.arrayBuffer(); if (testCase.expect == null) { @@ -3260,16 +3245,14 @@ Deno.test( let count = 0; const server = Deno.serve({ async onListen({ port }: { port: number }) { - const client = Deno.createHttpClient({}); - const res1 = await fetch(`http://localhost:${port}/`, { client }); + const res1 = await fetch(`http://localhost:${port}/`); assertEquals(await res1.text(), "hello world 1"); - const res2 = await fetch(`http://localhost:${port}/`, { client }); + const res2 = await fetch(`http://localhost:${port}/`); assertEquals(await res2.text(), "hello world 2"); promise.resolve(); ac.abort(); - client.close(); }, signal: ac.signal, }, () => { @@ -3322,16 +3305,13 @@ Deno.test( try { const port = await listeningPromise; - const client = Deno.createHttpClient({}); const resp = await fetch(`http://localhost:${port}/`, { headers: { connection: "close" }, method: "POST", body: '{"sus":true}', - client, }); const text = await resp.text(); assertEquals(text, "ok"); - client.close(); } finally { ac.abort(); await server.finished; |