summaryrefslogtreecommitdiff
path: root/tests/unit/serve_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/serve_test.ts')
-rw-r--r--tests/unit/serve_test.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 8978c4f7e..74628ace1 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -23,6 +23,7 @@ const {
addTrailers,
serveHttpOnListener,
serveHttpOnConnection,
+ getCachedAbortSignal,
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal];
@@ -2838,6 +2839,34 @@ for (const delay of ["delay", "nodelay"]) {
}
}
+// Test for the internal implementation detail of cached request signals. Ensure that the request's
+// signal is aborted if we try to access it after the request has been completed.
+Deno.test(
+ { permissions: { net: true } },
+ async function httpServerSignalCancelled() {
+ let stashedRequest;
+ const { finished, abort } = await makeServer((req) => {
+ // The cache signal is `undefined` because it has not been requested
+ assertEquals(getCachedAbortSignal(req), undefined);
+ stashedRequest = req;
+ return new Response("ok");
+ });
+ await (await fetch(`http://localhost:${servePort}`)).text();
+ abort();
+ await finished;
+
+ // `false` is a semaphore for a signal that should be aborted on creation
+ assertEquals(getCachedAbortSignal(stashedRequest!), false);
+ // Requesting the signal causes it to be materialized
+ assert(stashedRequest!.signal.aborted);
+ // The cached signal is now a full `AbortSignal`
+ assertEquals(
+ getCachedAbortSignal(stashedRequest!).constructor,
+ AbortSignal,
+ );
+ },
+);
+
Deno.test(
{ permissions: { net: true } },
async function httpServerCancelFetch() {