diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/serve_test.ts | 57 | ||||
-rw-r--r-- | tests/unit/test_util.ts | 15 |
2 files changed, 64 insertions, 8 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index f7f01076b..ff77578e6 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -11,6 +11,7 @@ import { curlRequest, curlRequestWithStdErr, execCode, + execCode3, fail, tmpUnixSocketPath, } from "./test_util.ts"; @@ -3985,3 +3986,59 @@ Deno.test( assert(respText === "Internal Server Error"); }, ); + +Deno.test( + { + permissions: { net: true, run: true, read: true }, + ignore: Deno.build.os !== "linux", + }, + async function gzipFlushResponseStream() { + const { promise, resolve } = Promise.withResolvers<void>(); + const ac = new AbortController(); + + console.log("Starting server", servePort); + let timer: number | undefined = undefined; + let _controller; + + const server = Deno.serve( + { + port: servePort, + onListen: onListen(resolve), + signal: ac.signal, + }, + () => { + const body = new ReadableStream({ + start(controller) { + timer = setInterval(() => { + const message = `It is ${new Date().toISOString()}\n`; + controller.enqueue(new TextEncoder().encode(message)); + }, 1000); + _controller = controller; + }, + cancel() { + if (timer !== undefined) { + clearInterval(timer); + } + }, + }); + return new Response(body, { + headers: { + "content-type": "text/plain", + "x-content-type-options": "nosniff", + }, + }); + }, + ); + await promise; + const e = await execCode3("/usr/bin/sh", [ + "-c", + `curl --stderr - -N --compressed --no-progress-meter http://localhost:${servePort}`, + ]); + await e.waitStdoutText("It is "); + clearTimeout(timer); + _controller!.close(); + await e.finished(); + ac.abort(); + await server.finished; + }, +); diff --git a/tests/unit/test_util.ts b/tests/unit/test_util.ts index ba9bf1839..db2585ebd 100644 --- a/tests/unit/test_util.ts +++ b/tests/unit/test_util.ts @@ -35,14 +35,9 @@ export function execCode(code: string): Promise<readonly [number, string]> { return execCode2(code).finished(); } -export function execCode2(code: string) { - const command = new Deno.Command(Deno.execPath(), { - args: [ - "eval", - "--unstable", - "--no-check", - code, - ], +export function execCode3(cmd: string, args: string[]) { + const command = new Deno.Command(cmd, { + args, stdout: "piped", stderr: "inherit", }); @@ -82,6 +77,10 @@ export function execCode2(code: string) { }; } +export function execCode2(code: string) { + return execCode3(Deno.execPath(), ["eval", "--unstable", "--no-check", code]); +} + export function tmpUnixSocketPath(): string { const folder = Deno.makeTempDirSync(); return join(folder, "socket"); |