From eed2598e6cf1db643b4edd07b5eff94c59eb9408 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Wed, 24 Apr 2024 14:03:37 -0400 Subject: 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. --- tests/unit/serve_test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests') 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(); const request2Aborted = Promise.withResolvers(); - 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); }, ); -- cgit v1.2.3