summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-04-20 18:16:44 +0530
committerGitHub <noreply@github.com>2022-04-20 18:16:44 +0530
commit57a8fc37fc99491fa2559694f78af52a597bc501 (patch)
treeb6d3bd41faa72dfeec4643e5fbb68a669ca03e79 /cli/tests
parent3833d37b15e1e8380efd1a9eea956a8b33745555 (diff)
perf(http): optimize `ReadableStream`s backed by a resource (#14284)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/http_test.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 37c827b9b..f48f314db 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -854,6 +854,45 @@ Deno.test({ permissions: { net: true } }, async function httpServerPanic() {
listener.close();
});
+Deno.test(
+ { permissions: { net: true, write: true, read: true } },
+ async function httpServerClosedStream() {
+ const listener = Deno.listen({ port: 4502 });
+
+ const client = await Deno.connect({ port: 4502 });
+ await client.write(new TextEncoder().encode(
+ `GET / HTTP/1.0\r\n\r\n`,
+ ));
+
+ const conn = await listener.accept();
+ const httpConn = Deno.serveHttp(conn);
+ const ev = await httpConn.nextRequest();
+ const { respondWith } = ev!;
+
+ const tmpFile = await Deno.makeTempFile();
+ const file = await Deno.open(tmpFile, { write: true, read: true });
+ await file.write(new TextEncoder().encode("hello"));
+
+ const reader = await file.readable.getReader();
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ assert(value);
+ }
+
+ try {
+ await respondWith(new Response(file.readable));
+ fail("The stream should've been locked");
+ } catch {
+ // pass
+ }
+
+ httpConn.close();
+ listener.close();
+ client.close();
+ },
+);
+
// https://github.com/denoland/deno/issues/11595
Deno.test(
{ permissions: { net: true } },