diff options
author | Luca Casonato <hello@lcas.dev> | 2023-09-16 07:48:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-16 07:48:31 +0200 |
commit | 430b63c2c4d6567a77e77980058ef13b45a9f30e (patch) | |
tree | 714fef4813a5614ccdd17b681f30e3bd0b4057bd /cli/tests/unit/fetch_test.ts | |
parent | bf0760411336ce5ebb1c103f766c8154af478414 (diff) |
perf: improve async op santizer speed and accuracy (#20501)
This commit improves async op sanitizer speed by only delaying metrics
collection if there are pending ops. This
results in a speedup of around 30% for small CPU bound unit tests.
It performs this check and possible delay on every collection now,
fixing an issue with parent test leaks into steps.
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 83386d2ee..4b6f3450d 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1752,7 +1752,8 @@ 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 response = await fetch(`http://${addr}/`); + const client = Deno.createHttpClient({}); + const response = await fetch(`http://${addr}/`, { client }); const res = await response.arrayBuffer(); const buf = new TextEncoder().encode(data); @@ -1760,6 +1761,7 @@ Deno.test( assertEquals(new Uint8Array(res), buf); listener.close(); + client.close(); }, ); @@ -1781,21 +1783,23 @@ 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}/`); + await fetch(`http://${addr}/`, { client }); }, TypeError, "invalid content-length parsed", ); listener.close(); + client.close(); }, ); Deno.test( { permissions: { net: true } }, - async function fetchWithInvalidContentLength(): Promise< + async function fetchWithInvalidContentLength2(): Promise< void > { const addr = `127.0.0.1:${listenPort}`; @@ -1807,7 +1811,8 @@ Deno.test( ); const listener = invalidServer(addr, body); - const response = await fetch(`http://${addr}/`); + const client = Deno.createHttpClient({}); + const response = await fetch(`http://${addr}/`, { client }); // If content-length < totalLength, a maximum of content-length bytes // should be returned. @@ -1817,12 +1822,13 @@ Deno.test( assertEquals(new Uint8Array(res), buf.subarray(contentLength)); listener.close(); + client.close(); }, ); Deno.test( { permissions: { net: true } }, - async function fetchWithInvalidContentLength(): Promise< + async function fetchWithInvalidContentLength3(): Promise< void > { const addr = `127.0.0.1:${listenPort}`; @@ -1834,7 +1840,8 @@ Deno.test( ); const listener = invalidServer(addr, body); - const response = await fetch(`http://${addr}/`); + const client = Deno.createHttpClient({}); + const response = await fetch(`http://${addr}/`, { client }); // If content-length > totalLength, a maximum of content-length bytes // should be returned. await assertRejects( @@ -1846,6 +1853,7 @@ Deno.test( ); listener.close(); + client.close(); }, ); @@ -1935,10 +1943,12 @@ Deno.test( }, }); + const client = Deno.createHttpClient({}); const err = await assertRejects(() => fetch(`http://localhost:${listenPort}/`, { body: stream, method: "POST", + client, }) ); @@ -1948,6 +1958,7 @@ Deno.test( assertEquals(err.cause.message, "foo"); await server; + client.close(); }, ); |