summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-05-19 13:39:52 +0100
committerBert Belder <bertbelder@gmail.com>2021-05-31 16:37:30 +0200
commit218ba031f06919b1871b4d360e5ae6c5cc777f35 (patch)
treeed6439bb985f9457fbec650ebe8b339c911f4cd9 /cli/tests
parenta1125765ec8ef5d13ed49ad5cceadb0b41202be4 (diff)
fix(runtime/http): expose nextRequest() errors in respondWith() (#10384)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/http_test.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index ab43323bd..d4c35545f 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -272,3 +272,48 @@ unitTest(
await promise;
},
);
+
+unitTest(
+ { perms: { net: true } },
+ async function httpServerNextRequestErrorExposedInResponse() {
+ const promise = (async () => {
+ const listener = Deno.listen({ port: 4501 });
+ const conn = await listener.accept();
+ const httpConn = Deno.serveHttp(conn);
+ const event = await httpConn.nextRequest();
+ assert(event);
+ // Start polling for the next request before awaiting response.
+ const nextRequestPromise = httpConn.nextRequest();
+ const { respondWith } = event;
+ await assertThrowsAsync(
+ async () => {
+ let interval = 0;
+ await respondWith(
+ new Response(
+ new ReadableStream({
+ start(controller) {
+ interval = setInterval(() => {
+ const message = `data: ${Date.now()}\n\n`;
+ controller.enqueue(new TextEncoder().encode(message));
+ }, 200);
+ },
+ cancel() {
+ clearInterval(interval);
+ },
+ }),
+ ),
+ );
+ },
+ Deno.errors.Http,
+ "connection closed",
+ );
+ // The error from `op_http_request_next` reroutes to `respondWith()`.
+ assertEquals(await nextRequestPromise, null);
+ listener.close();
+ })();
+
+ const resp = await fetch("http://127.0.0.1:4501/");
+ await resp.body!.cancel();
+ await promise;
+ },
+);