1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 16:42:21 -05:00

fix(http/server): flaky test on Windows (#6188)

This commit is contained in:
Marcos Casagrande 2020-06-09 00:10:29 +02:00 committed by GitHub
parent 1f4520d2bd
commit 50a70f4ece
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,7 @@ import {
assertStringContains, assertStringContains,
assertThrowsAsync, assertThrowsAsync,
} from "../testing/asserts.ts"; } 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 { BufReader, BufWriter } from "../io/bufio.ts";
import { delay } from "../async/delay.ts"; import { delay } from "../async/delay.ts";
import { encode, decode } from "../encoding/utf8.ts"; import { encode, decode } from "../encoding/utf8.ts";
@ -549,40 +549,29 @@ test({
test({ test({
name: "serveTLS Invalid Cert", name: "serveTLS Invalid Cert",
fn: async (): Promise<void> => { fn: async (): Promise<void> => {
// Runs a simple server as another process async function iteratorReq(server: Server): Promise<void> {
const p = Deno.run({ for await (const req of server) {
cmd: [ await req.respond({ body: new TextEncoder().encode("Hello HTTPS") });
Deno.execPath(), }
"run", }
"--allow-net", const port = 9122;
"--allow-read", const tlsOptions = {
"http/testdata/simple_https_server.ts", hostname: "localhost",
], port,
stdout: "piped", certFile: "./http/testdata/tls/localhost.crt",
}); keyFile: "./http/testdata/tls/localhost.key",
};
let serverIsRunning = true; const server = serveTLS(tlsOptions);
const statusPromise = p const p = iteratorReq(server);
.status()
.then((): void => {
serverIsRunning = false;
})
.catch((_): void => {}); // Ignores the error when closing the process.
try { 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 // Invalid certificate, connection should throw
// but should not crash the server // but should not crash the server
assertThrowsAsync( assertThrowsAsync(
() => () =>
Deno.connectTls({ Deno.connectTls({
hostname: "localhost", hostname: "localhost",
port: 4503, port,
// certFile // certFile
}), }),
Deno.errors.InvalidData Deno.errors.InvalidData
@ -591,7 +580,7 @@ test({
// Valid request after invalid // Valid request after invalid
const conn = await Deno.connectTls({ const conn = await Deno.connectTls({
hostname: "localhost", hostname: "localhost",
port: 4503, port,
certFile: "http/testdata/tls/RootCA.pem", certFile: "http/testdata/tls/RootCA.pem",
}); });
@ -605,13 +594,10 @@ test({
conn.close(); conn.close();
const resStr = new TextDecoder().decode(res.subarray(0, nread)); const resStr = new TextDecoder().decode(res.subarray(0, nread));
assert(resStr.includes("Hello HTTPS")); assert(resStr.includes("Hello HTTPS"));
assert(serverIsRunning);
} finally { } finally {
// Stops the sever and allows `p.status()` promise to resolve // Stops the sever and allows `p.status()` promise to resolve
Deno.kill(p.pid, Deno.Signal.SIGKILL); server.close();
await statusPromise; await p;
p.stdout!.close();
p.close();
} }
}, },
}); });