diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-10-10 05:31:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-10 05:31:23 -0400 |
commit | e7562eed8c816cd0d97aab6b818d7c8453dbaa2b (patch) | |
tree | c5a9f536e79d2c8d2d02897511a9138acaf35394 /std/http/racing_server_test.ts | |
parent | 3882c9d19a641e0c919f1350d87c6d7ee280cf78 (diff) | |
parent | 93f7f00c956c14620ef031626f124b57397ca867 (diff) |
Merge deno_std in main repo (#3091)
The history of deno_std is persevered but rewritten to update links to issues and PRs
Fixes denoland/deno_std#603
Diffstat (limited to 'std/http/racing_server_test.ts')
m--------- | std | 0 | ||||
-rw-r--r-- | std/http/racing_server_test.ts | 65 |
2 files changed, 65 insertions, 0 deletions
diff --git a/std b/std deleted file mode 160000 -Subproject 43aafbf33285753e7b42230f0eb7969b300f71c diff --git a/std/http/racing_server_test.ts b/std/http/racing_server_test.ts new file mode 100644 index 000000000..b66986247 --- /dev/null +++ b/std/http/racing_server_test.ts @@ -0,0 +1,65 @@ +const { dial, run } = Deno; + +import { test, runIfMain } from "../testing/mod.ts"; +import { assert, assertEquals } from "../testing/asserts.ts"; +import { BufReader } from "../io/bufio.ts"; +import { TextProtoReader } from "../textproto/mod.ts"; + +let server: Deno.Process; +async function startServer(): Promise<void> { + server = run({ + args: [Deno.execPath(), "run", "-A", "http/racing_server.ts"], + stdout: "piped" + }); + // Once racing server is ready it will write to its stdout. + const r = new TextProtoReader(new BufReader(server.stdout!)); + const s = await r.readLine(); + assert(s !== Deno.EOF && s.includes("Racing server listening...")); +} +function killServer(): void { + server.close(); + server.stdout!.close(); +} + +const input = `GET / HTTP/1.1 + +GET / HTTP/1.1 + +GET / HTTP/1.1 + +GET / HTTP/1.1 + +`; +const HUGE_BODY_SIZE = 1024 * 1024; +const output = `HTTP/1.1 200 OK +content-length: 8 + +Hello 1 +HTTP/1.1 200 OK +content-length: ${HUGE_BODY_SIZE} + +${"a".repeat(HUGE_BODY_SIZE)}HTTP/1.1 200 OK +content-length: ${HUGE_BODY_SIZE} + +${"b".repeat(HUGE_BODY_SIZE)}HTTP/1.1 200 OK +content-length: 8 + +World 4 +`; + +test(async function serverPipelineRace(): Promise<void> { + await startServer(); + + const conn = await dial({ port: 4501 }); + const r = new TextProtoReader(new BufReader(conn)); + await conn.write(new TextEncoder().encode(input)); + const outLines = output.split("\n"); + // length - 1 to disregard last empty line + for (let i = 0; i < outLines.length - 1; i++) { + const s = await r.readLine(); + assertEquals(s, outLines[i]); + } + killServer(); +}); + +runIfMain(import.meta); |