summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-11-17 16:19:00 -0700
committerGitHub <noreply@github.com>2023-11-17 16:19:00 -0700
commit23119fc1d411de1f48c6542aed30d0876caf2aea (patch)
treea260ecd288a936fc0e139f494463af8468e19842
parent20bf697ba6fd2aa769342c8a3b343ae265e46330 (diff)
test(cli): http test reliability fixes (#21246)
-rw-r--r--cli/tests/unit/http_test.ts4
-rw-r--r--cli/tests/unit/serve_test.ts33
2 files changed, 24 insertions, 13 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 8c7bf9974..ac3b3d66f 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -1136,7 +1136,7 @@ Deno.test(
{ permissions: { net: true } },
async function droppedConnSenderNoPanic() {
async function server() {
- const listener = Deno.listen({ port: 8000 });
+ const listener = Deno.listen({ port: listenPort });
const conn = await listener.accept();
const http = Deno.serveHttp(conn);
const evt = await http.nextRequest();
@@ -1151,7 +1151,7 @@ Deno.test(
async function client() {
try {
- const resp = await fetch("http://127.0.0.1:8000/");
+ const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
await resp.body?.cancel();
} catch {
// Ignore error
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index 59334039a..b1fbb2e89 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -3640,22 +3640,22 @@ Deno.test(
async function httpServeCurlH2C() {
const ac = new AbortController();
const server = Deno.serve(
- { signal: ac.signal },
+ { port: servePort, signal: ac.signal },
() => new Response("hello world!"),
);
assertEquals(
"hello world!",
- await curlRequest(["http://localhost:8000/path"]),
+ await curlRequest([`http://localhost:${servePort}/path`]),
);
assertEquals(
"hello world!",
- await curlRequest(["http://localhost:8000/path", "--http2"]),
+ await curlRequest([`http://localhost:${servePort}/path`, "--http2"]),
);
assertEquals(
"hello world!",
await curlRequest([
- "http://localhost:8000/path",
+ `http://localhost:${servePort}/path`,
"--http2",
"--http2-prior-knowledge",
]),
@@ -3712,6 +3712,7 @@ Deno.test(
const server = Deno.serve(
{
signal: ac.signal,
+ port: servePort,
cert: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt"),
key: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key"),
},
@@ -3720,16 +3721,20 @@ Deno.test(
assertEquals(
"hello world!",
- await curlRequest(["https://localhost:8000/path", "-k"]),
+ await curlRequest([`https://localhost:${servePort}/path`, "-k"]),
);
assertEquals(
"hello world!",
- await curlRequest(["https://localhost:8000/path", "-k", "--http2"]),
+ await curlRequest([
+ `https://localhost:${servePort}/path`,
+ "-k",
+ "--http2",
+ ]),
);
assertEquals(
"hello world!",
await curlRequest([
- "https://localhost:8000/path",
+ `https://localhost:${servePort}/path`,
"-k",
"--http2",
"--http2-prior-knowledge",
@@ -3742,12 +3747,15 @@ Deno.test(
);
async function curlRequest(args: string[]) {
- const { success, stdout } = await new Deno.Command("curl", {
+ const { success, stdout, stderr } = await new Deno.Command("curl", {
args,
stdout: "piped",
- stderr: "null",
+ stderr: "piped",
}).output();
- assert(success);
+ assert(
+ success,
+ `Failed to cURL ${args}: stdout\n\n${stdout}\n\nstderr:\n\n${stderr}`,
+ );
return new TextDecoder().decode(stdout);
}
@@ -3757,7 +3765,10 @@ async function curlRequestWithStdErr(args: string[]) {
stdout: "piped",
stderr: "piped",
}).output();
- assert(success);
+ assert(
+ success,
+ `Failed to cURL ${args}: stdout\n\n${stdout}\n\nstderr:\n\n${stderr}`,
+ );
return [new TextDecoder().decode(stdout), new TextDecoder().decode(stderr)];
}