Skip to content

Commit

Permalink
test(cli): http test reliability fixes (denoland#21246)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Nov 17, 2023
1 parent 20bf697 commit 23119fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cli/tests/unit/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -1151,7 +1151,7 @@ Deno.test(

async function client() {
try {
const resp = await fetch("http:https://127.0.0.1:8000/");
const resp = await fetch(`http:https://127.0.0.1:${listenPort}/`);
await resp.body?.cancel();
} catch {
// Ignore error
Expand Down
33 changes: 22 additions & 11 deletions cli/tests/unit/serve_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:https://localhost:8000/path"]),
await curlRequest([`http:https://localhost:${servePort}/path`]),
);
assertEquals(
"hello world!",
await curlRequest(["http:https://localhost:8000/path", "--http2"]),
await curlRequest([`http:https://localhost:${servePort}/path`, "--http2"]),
);
assertEquals(
"hello world!",
await curlRequest([
"http:https://localhost:8000/path",
`http:https://localhost:${servePort}/path`,
"--http2",
"--http2-prior-knowledge",
]),
Expand Down Expand Up @@ -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"),
},
Expand All @@ -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",
Expand All @@ -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);
}

Expand All @@ -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)];
}

Expand Down

0 comments on commit 23119fc

Please sign in to comment.