diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-04-24 14:03:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 14:03:37 -0400 |
commit | eed2598e6cf1db643b4edd07b5eff94c59eb9408 (patch) | |
tree | 0320981bba82c78647b9cf335793381400093ad9 /tests | |
parent | b60822f6e0e3c1f3e360657cfb67c114df2e7032 (diff) |
feat(ext/http): Implement request.signal for Deno.serve (#23425)
When the response has been successfully send, we abort the
`Request.signal` property to indicate that all resources associated with
this transaction may be torn down.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/serve_test.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 048529ae9..32d05056a 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -2843,7 +2843,20 @@ Deno.test( async function httpServerCancelFetch() { const request2 = Promise.withResolvers<void>(); const request2Aborted = Promise.withResolvers<string>(); - const { finished, abort } = await makeServer(async (req) => { + let completed = 0; + let aborted = 0; + const { finished, abort } = await makeServer(async (req, context) => { + context.completed.then(() => { + console.log("completed"); + completed++; + }).catch(() => { + console.log("completed (error)"); + completed++; + }); + req.signal.onabort = () => { + console.log("aborted", req.url); + aborted++; + }; if (req.url.endsWith("/1")) { const fetchRecursive = await fetch(`http://localhost:${servePort}/2`); return new Response(fetchRecursive.body); @@ -2871,6 +2884,8 @@ Deno.test( abort(); await finished; + assertEquals(completed, 2); + assertEquals(aborted, 2); }, ); |