summaryrefslogtreecommitdiff
path: root/http/server_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'http/server_test.ts')
-rw-r--r--http/server_test.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/http/server_test.ts b/http/server_test.ts
index 04ff4ba15..da1a08dc0 100644
--- a/http/server_test.ts
+++ b/http/server_test.ts
@@ -6,6 +6,7 @@
// https://github.com/golang/go/blob/master/src/net/http/responsewrite_test.go
const { Buffer } = Deno;
+import { TextProtoReader } from "../textproto/mod.ts";
import { test, runIfMain } from "../testing/mod.ts";
import { assert, assertEquals, assertNotEquals } from "../testing/asserts.ts";
import {
@@ -15,6 +16,7 @@ import {
readRequest,
parseHTTPVersion
} from "./server.ts";
+import { delay } from "../util/async.ts";
import {
BufReader,
BufWriter,
@@ -456,4 +458,47 @@ test({
}
});
+test({
+ name: "[http] destroyed connection",
+ async fn(): Promise<void> {
+ // TODO: don't skip on windows when process.kill is implemented on windows.
+ if (Deno.build.os === "win") {
+ return;
+ }
+ // Runs a simple server as another process
+ const p = Deno.run({
+ args: [Deno.execPath, "http/testdata/simple_server.ts", "--allow-net"],
+ stdout: "piped"
+ });
+
+ try {
+ const r = new TextProtoReader(new BufReader(p.stdout!));
+ const s = await r.readLine();
+ assert(s !== Deno.EOF && s.includes("server listening"));
+
+ let serverIsRunning = true;
+ p.status().then(
+ (): void => {
+ serverIsRunning = false;
+ }
+ );
+
+ await delay(100);
+
+ // Reqeusts to the server and immediately closes the connection
+ const conn = await Deno.dial("tcp", "127.0.0.1:4502");
+ await conn.write(new TextEncoder().encode("GET / HTTP/1.0\n\n"));
+ conn.close();
+
+ // Waits for the server to handle the above (broken) request
+ await delay(100);
+
+ assert(serverIsRunning);
+ } finally {
+ // Stops the sever.
+ p.kill(Deno.Signal.SIGINT);
+ }
+ }
+});
+
runIfMain(import.meta);