summaryrefslogtreecommitdiff
path: root/http/racing_server_test.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-04-13 12:23:56 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-04-13 15:23:56 -0400
commit236cedc7cba21132a2280c86ae4cf44c057ab5d8 (patch)
treebbaede3c311c377d9b4a22dc365875f7f642185f /http/racing_server_test.ts
parent733fbfd555a2db3365ac8ce19bc11e4a97fcfd47 (diff)
Enforce HTTP/1.1 pipeline response order (denoland/deno_std#331)
Original: https://github.com/denoland/deno_std/commit/144ef0e08d589fad2ca19eb4ef1ea20f1749bb5c
Diffstat (limited to 'http/racing_server_test.ts')
-rw-r--r--http/racing_server_test.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/http/racing_server_test.ts b/http/racing_server_test.ts
new file mode 100644
index 000000000..0c1a5c65f
--- /dev/null
+++ b/http/racing_server_test.ts
@@ -0,0 +1,65 @@
+const { dial, run } = Deno;
+
+import { test } 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;
+async function startServer(): Promise<void> {
+ server = run({
+ args: ["deno", "-A", "http/racing_server.ts"],
+ stdout: "piped"
+ });
+ // Once fileServer is ready it will write to its stdout.
+ const r = new TextProtoReader(new BufReader(server.stdout));
+ const [s, err] = await r.readLine();
+ assert(err == null);
+ assert(s.includes("Racing server listening..."));
+}
+function killServer(): void {
+ server.close();
+ server.stdout.close();
+}
+
+let input = `GET / HTTP/1.1
+
+GET / HTTP/1.1
+
+GET / HTTP/1.1
+
+GET / HTTP/1.1
+
+`;
+const HUGE_BODY_SIZE = 1024 * 1024;
+let 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("tcp", "127.0.0.1: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, err] = await r.readLine();
+ assert(!err);
+ assertEquals(s, outLines[i]);
+ }
+ killServer();
+});