Skip to content

Commit

Permalink
fix: flaky http/file_server.ts tests (#3717)
Browse files Browse the repository at this point in the history
* fix: #3716

* additional fix

* revert

* fix

* fix

* rerun

* rerun

* rerun

---------

Co-authored-by: Yoshiya Hinosawa <[email protected]>
  • Loading branch information
iuioiua and kt3k authored Oct 26, 2023
1 parent ef479c2 commit f64ea09
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions http/file_server_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertStringIncludes } from "../assert/mod.ts";
import {
assert,
assertEquals,
assertFalse,
assertStringIncludes,
} from "../assert/mod.ts";
import { stub } from "../testing/mock.ts";
import { iterateReader } from "../streams/iterate_reader.ts";
import { writeAll } from "../streams/write_all.ts";
Expand Down Expand Up @@ -540,31 +545,22 @@ Deno.test(
async function () {
await startTlsFileServer();
try {
// Valid request after invalid
const conn = await Deno.connectTls({
hostname: "localhost",
port: 4577,
certFile: join(testdataDir, "tls/RootCA.pem"),
});

await writeAll(
conn,
new TextEncoder().encode("GET / HTTP/1.0\r\n\r\n"),
const caCert = await Deno.readTextFile(
join(testdataDir, "tls/RootCA.pem"),
);
const res = new Uint8Array(128 * 1024);
const nread = await conn.read(res);
assert(nread !== null);
conn.close();
const page = new TextDecoder().decode(res.subarray(0, nread));
assert(page.includes("<title>Deno File Server</title>"));
const client = Deno.createHttpClient({ caCerts: [caCert] });
const res = await fetch("https://localhost:4577/", { client });
client.close();

assertStringIncludes(await res.text(), "<title>Deno File Server</title>");
} finally {
await killFileServer();
}
},
);

Deno.test("partial TLS arguments fail", async function () {
const fileServer = new Deno.Command(Deno.execPath(), {
const command = new Deno.Command(Deno.execPath(), {
args: [
"run",
"--no-check",
Expand All @@ -581,23 +577,14 @@ Deno.test("partial TLS arguments fail", async function () {
`4578`,
],
cwd: moduleDir,
stdout: "piped",
stderr: "null",
});
child = fileServer.spawn();
try {
// Once fileServer is ready it will write to its stdout.
const r = child.stdout.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream());
const reader = r.getReader();
const res = await reader.read();
assert(
!res.done && res.value.includes("--key and --cert are required for TLS"),
);
reader.releaseLock();
} finally {
await killFileServer();
}
const { stdout, success } = await command.output();
assertFalse(success);
assertStringIncludes(
new TextDecoder().decode(stdout),
"--key and --cert are required for TLS",
);
});

Deno.test("file_server disable dir listings", async function () {
Expand Down

0 comments on commit f64ea09

Please sign in to comment.