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/fetch_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/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 4b6f3450d..c1f11093b 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1752,8 +1752,7 @@ Deno.test( // if transfer-encoding is sent, content-length is ignored // even if it has an invalid value (content-length > totalLength) const listener = invalidServer(addr, body); - const client = Deno.createHttpClient({}); - const response = await fetch(`http://${addr}/`, { client }); + const response = await fetch(`http://${addr}/`); const res = await response.arrayBuffer(); const buf = new TextEncoder().encode(data); @@ -1761,7 +1760,6 @@ Deno.test( assertEquals(new Uint8Array(res), buf); listener.close(); - client.close(); }, ); @@ -1783,17 +1781,15 @@ Deno.test( // It should fail if multiple content-length headers with different values are sent const listener = invalidServer(addr, body); - const client = Deno.createHttpClient({}); await assertRejects( async () => { - await fetch(`http://${addr}/`, { client }); + await fetch(`http://${addr}/`); }, TypeError, "invalid content-length parsed", ); listener.close(); - client.close(); }, ); @@ -1811,8 +1807,7 @@ Deno.test( ); const listener = invalidServer(addr, body); - const client = Deno.createHttpClient({}); - const response = await fetch(`http://${addr}/`, { client }); + const response = await fetch(`http://${addr}/`); // If content-length < totalLength, a maximum of content-length bytes // should be returned. @@ -1822,7 +1817,6 @@ Deno.test( assertEquals(new Uint8Array(res), buf.subarray(contentLength)); listener.close(); - client.close(); }, ); @@ -1840,8 +1834,7 @@ Deno.test( ); const listener = invalidServer(addr, body); - const client = Deno.createHttpClient({}); - const response = await fetch(`http://${addr}/`, { client }); + const response = await fetch(`http://${addr}/`); // If content-length > totalLength, a maximum of content-length bytes // should be returned. await assertRejects( @@ -1853,7 +1846,6 @@ Deno.test( ); listener.close(); - client.close(); }, ); @@ -1943,12 +1935,10 @@ Deno.test( }, }); - const client = Deno.createHttpClient({}); const err = await assertRejects(() => fetch(`http://localhost:${listenPort}/`, { body: stream, method: "POST", - client, }) ); @@ -1958,7 +1948,6 @@ Deno.test( assertEquals(err.cause.message, "foo"); await server; - client.close(); }, ); |