summaryrefslogtreecommitdiff
path: root/std/http/server_test.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-06-09 00:10:29 +0200
committerGitHub <noreply@github.com>2020-06-09 00:10:29 +0200
commit50a70f4ece1283e2f2d83bbbb3790863a2fab7f2 (patch)
tree8831025052774681733f0c259e589b0da420175d /std/http/server_test.ts
parent1f4520d2bd6f7ba10a65aaa3331d67799f9e5991 (diff)
fix(http/server): flaky test on Windows (#6188)
Diffstat (limited to 'std/http/server_test.ts')
-rw-r--r--std/http/server_test.ts52
1 files changed, 19 insertions, 33 deletions
diff --git a/std/http/server_test.ts b/std/http/server_test.ts
index 93b117059..d522b9a8f 100644
--- a/std/http/server_test.ts
+++ b/std/http/server_test.ts
@@ -13,7 +13,7 @@ import {
assertStringContains,
assertThrowsAsync,
} from "../testing/asserts.ts";
-import { Response, ServerRequest, Server, serve } from "./server.ts";
+import { Response, ServerRequest, Server, serve, serveTLS } from "./server.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { delay } from "../async/delay.ts";
import { encode, decode } from "../encoding/utf8.ts";
@@ -549,40 +549,29 @@ test({
test({
name: "serveTLS Invalid Cert",
fn: async (): Promise<void> => {
- // Runs a simple server as another process
- const p = Deno.run({
- cmd: [
- Deno.execPath(),
- "run",
- "--allow-net",
- "--allow-read",
- "http/testdata/simple_https_server.ts",
- ],
- stdout: "piped",
- });
-
- let serverIsRunning = true;
- const statusPromise = p
- .status()
- .then((): void => {
- serverIsRunning = false;
- })
- .catch((_): void => {}); // Ignores the error when closing the process.
+ async function iteratorReq(server: Server): Promise<void> {
+ for await (const req of server) {
+ await req.respond({ body: new TextEncoder().encode("Hello HTTPS") });
+ }
+ }
+ const port = 9122;
+ const tlsOptions = {
+ hostname: "localhost",
+ port,
+ certFile: "./http/testdata/tls/localhost.crt",
+ keyFile: "./http/testdata/tls/localhost.key",
+ };
+ const server = serveTLS(tlsOptions);
+ const p = iteratorReq(server);
try {
- const r = new TextProtoReader(new BufReader(p.stdout!));
- const s = await r.readLine();
- assert(
- s !== null && s.includes("server listening"),
- "server must be started"
- );
// Invalid certificate, connection should throw
// but should not crash the server
assertThrowsAsync(
() =>
Deno.connectTls({
hostname: "localhost",
- port: 4503,
+ port,
// certFile
}),
Deno.errors.InvalidData
@@ -591,7 +580,7 @@ test({
// Valid request after invalid
const conn = await Deno.connectTls({
hostname: "localhost",
- port: 4503,
+ port,
certFile: "http/testdata/tls/RootCA.pem",
});
@@ -605,13 +594,10 @@ test({
conn.close();
const resStr = new TextDecoder().decode(res.subarray(0, nread));
assert(resStr.includes("Hello HTTPS"));
- assert(serverIsRunning);
} finally {
// Stops the sever and allows `p.status()` promise to resolve
- Deno.kill(p.pid, Deno.Signal.SIGKILL);
- await statusPromise;
- p.stdout!.close();
- p.close();
+ server.close();
+ await p;
}
},
});