mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
chore(cli): Reduce port conflict in tests (#19988)
Ports are still occasionally causing CI flake -- allocate and separate ports further for fetch/http tests.
This commit is contained in:
parent
2fd87471e8
commit
43877f1209
2 changed files with 114 additions and 102 deletions
|
@ -10,7 +10,7 @@ import {
|
|||
} from "./test_util.ts";
|
||||
import { Buffer } from "../../../test_util/std/io/buffer.ts";
|
||||
|
||||
const listenPort = 4504;
|
||||
const listenPort = 4506;
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
|
@ -1909,7 +1909,7 @@ Deno.test(
|
|||
// https://github.com/denoland/deno/issues/18350
|
||||
{ ignore: Deno.build.os === "windows", permissions: { net: true } },
|
||||
async function fetchRequestBodyErrorCatchable() {
|
||||
const listener = Deno.listen({ hostname: "127.0.0.1", port: 4514 });
|
||||
const listener = Deno.listen({ hostname: "127.0.0.1", port: listenPort });
|
||||
const server = (async () => {
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
|
@ -1936,7 +1936,7 @@ Deno.test(
|
|||
});
|
||||
|
||||
const err = await assertRejects(() =>
|
||||
fetch("http://localhost:4514", {
|
||||
fetch(`http://localhost:${listenPort}/`, {
|
||||
body: stream,
|
||||
method: "POST",
|
||||
})
|
||||
|
|
|
@ -14,6 +14,9 @@ import {
|
|||
} from "./test_util.ts";
|
||||
import { join } from "../../../test_util/std/path/mod.ts";
|
||||
|
||||
const listenPort = 4507;
|
||||
const listenPort2 = 4508;
|
||||
|
||||
const {
|
||||
buildCaseInsensitiveCommaValueFinder,
|
||||
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
|
||||
|
@ -25,7 +28,7 @@ async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
|
|||
|
||||
const w = new BufWriter(conn);
|
||||
const r = new BufReader(conn);
|
||||
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
||||
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`;
|
||||
const writeResult = await w.write(encoder.encode(body));
|
||||
assertEquals(body.length, writeResult);
|
||||
await w.flush();
|
||||
|
@ -49,21 +52,21 @@ async function writeRequestAndReadResponse(conn: Deno.Conn): Promise<string> {
|
|||
Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
const reqEvent = await httpConn.nextRequest();
|
||||
assert(reqEvent);
|
||||
const { request, respondWith } = reqEvent;
|
||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
|
||||
assertEquals(new URL(request.url).href, `http://127.0.0.1:${listenPort}/`);
|
||||
assertEquals(await request.text(), "");
|
||||
await respondWith(
|
||||
new Response("Hello World", { headers: { "foo": "bar" } }),
|
||||
);
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
headers: { "connection": "close" },
|
||||
});
|
||||
const clone = resp.clone();
|
||||
|
@ -144,7 +147,7 @@ Deno.test(
|
|||
async function httpServerGetRequestBody() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -155,11 +158,11 @@ Deno.test(
|
|||
await respondWith(new Response("", { headers: {} }));
|
||||
})();
|
||||
|
||||
const conn = await Deno.connect({ port: 4501 });
|
||||
const conn = await Deno.connect({ port: listenPort });
|
||||
// Send GET request with a body + content-length.
|
||||
const encoder = new TextEncoder();
|
||||
const body =
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\nContent-Length: 5\r\n\r\n12345`;
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\nContent-Length: 5\r\n\r\n12345`;
|
||||
const writeResult = await conn.write(encoder.encode(body));
|
||||
assertEquals(body.length, writeResult);
|
||||
|
||||
|
@ -184,7 +187,7 @@ Deno.test(
|
|||
writer.close();
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -195,7 +198,7 @@ Deno.test(
|
|||
await respondWith(new Response(stream.readable));
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/");
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||
const respBody = await resp.text();
|
||||
assertEquals("hello world", respBody);
|
||||
await promise;
|
||||
|
@ -214,7 +217,7 @@ Deno.test(
|
|||
writer.close();
|
||||
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const evt = await httpConn.nextRequest();
|
||||
|
@ -225,14 +228,14 @@ Deno.test(
|
|||
await respondWith(new Response(""));
|
||||
|
||||
// TODO(ry) If we don't call httpConn.nextRequest() here we get "error sending
|
||||
// request for url (https://localhost:4501/): connection closed before
|
||||
// request for url (https://localhost:${listenPort}/): connection closed before
|
||||
// message completed".
|
||||
assertEquals(await httpConn.nextRequest(), null);
|
||||
|
||||
listener.close();
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
body: stream.readable,
|
||||
method: "POST",
|
||||
headers: { "connection": "close" },
|
||||
|
@ -247,7 +250,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerStreamDuplex() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -260,7 +263,7 @@ Deno.test(
|
|||
|
||||
const ts = new TransformStream();
|
||||
const writable = ts.writable.getWriter();
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
method: "POST",
|
||||
body: ts.readable,
|
||||
});
|
||||
|
@ -285,8 +288,8 @@ Deno.test(
|
|||
);
|
||||
|
||||
Deno.test({ permissions: { net: true } }, async function httpServerClose() {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const client = await Deno.connect({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const client = await Deno.connect({ port: listenPort });
|
||||
const httpConn = Deno.serveHttp(await listener.accept());
|
||||
client.close();
|
||||
const evt = await httpConn.nextRequest();
|
||||
|
@ -298,8 +301,8 @@ Deno.test({ permissions: { net: true } }, async function httpServerClose() {
|
|||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
async function httpServerInvalidMethod() {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const client = await Deno.connect({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const client = await Deno.connect({ port: listenPort });
|
||||
const httpConn = Deno.serveHttp(await listener.accept());
|
||||
await client.write(new Uint8Array([1, 2, 3]));
|
||||
await assertRejects(
|
||||
|
@ -319,7 +322,7 @@ Deno.test(
|
|||
{ permissions: { read: true, net: true } },
|
||||
async function httpServerWithTls() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listenTls({
|
||||
|
@ -336,7 +339,7 @@ Deno.test(
|
|||
await respondWith(new Response("Hello World"));
|
||||
|
||||
// TODO(ry) If we don't call httpConn.nextRequest() here we get "error sending
|
||||
// request for url (https://localhost:4501/): connection closed before
|
||||
// request for url (https://localhost:${listenPort}/): connection closed before
|
||||
// message completed".
|
||||
assertEquals(await httpConn.nextRequest(), null);
|
||||
|
||||
|
@ -360,7 +363,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerRegressionHang() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -372,7 +375,7 @@ Deno.test(
|
|||
await respondWith(new Response("response"));
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
method: "POST",
|
||||
body: "request",
|
||||
});
|
||||
|
@ -389,7 +392,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerCancelBodyOnResponseFailure() {
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const event = await httpConn.nextRequest();
|
||||
|
@ -424,7 +427,7 @@ Deno.test(
|
|||
listener.close();
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/");
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||
await resp.body!.cancel();
|
||||
await promise;
|
||||
},
|
||||
|
@ -434,7 +437,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerNextRequestErrorExposedInResponse() {
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const event = await httpConn.nextRequest();
|
||||
|
@ -469,7 +472,7 @@ Deno.test(
|
|||
listener.close();
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/");
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||
await resp.body!.cancel();
|
||||
await promise;
|
||||
},
|
||||
|
@ -479,7 +482,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerEmptyBlobResponse() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -489,7 +492,7 @@ Deno.test(
|
|||
await respondWith(new Response(new Blob([])));
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/");
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||
const respBody = await resp.text();
|
||||
assertEquals("", respBody);
|
||||
await promise;
|
||||
|
@ -515,11 +518,11 @@ Deno.test(
|
|||
}
|
||||
}
|
||||
|
||||
const l = Deno.listen({ port: 4500 });
|
||||
const l = Deno.listen({ port: listenPort });
|
||||
serve(l);
|
||||
|
||||
await delay(300);
|
||||
const res = await fetch("http://localhost:4500/");
|
||||
const res = await fetch(`http://localhost:${listenPort}/`);
|
||||
const _text = await res.text();
|
||||
|
||||
// Close connection and listener.
|
||||
|
@ -543,7 +546,7 @@ Deno.test(
|
|||
const httpConns: Deno.HttpConn[] = [];
|
||||
const promise = (async () => {
|
||||
let count = 0;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
for await (const conn of listener) {
|
||||
(async () => {
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
|
@ -560,7 +563,7 @@ Deno.test(
|
|||
}
|
||||
})();
|
||||
|
||||
const clientConn = await Deno.connect({ port: 4501 });
|
||||
const clientConn = await Deno.connect({ port: listenPort });
|
||||
|
||||
const r1 = await writeRequestAndReadResponse(clientConn);
|
||||
assertEquals(r1, "hello");
|
||||
|
@ -600,7 +603,7 @@ Deno.test(
|
|||
|
||||
const w = new BufWriter(conn);
|
||||
const r = new BufReader(conn);
|
||||
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
||||
const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`;
|
||||
const writeResult = await w.write(encoder.encode(body));
|
||||
assertEquals(body.length, writeResult);
|
||||
await w.flush();
|
||||
|
@ -645,7 +648,7 @@ Deno.test(
|
|||
}
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const finished = (async () => {
|
||||
const conn = await listener.accept();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -655,7 +658,7 @@ Deno.test(
|
|||
})();
|
||||
|
||||
// start a client
|
||||
const clientConn = await Deno.connect({ port: 4501 });
|
||||
const clientConn = await Deno.connect({ port: listenPort });
|
||||
|
||||
const r1 = await writeRequest(clientConn);
|
||||
assertEquals(r1, "0\n1\n2\n");
|
||||
|
@ -673,7 +676,7 @@ Deno.test(
|
|||
async function httpRequestLatin1Headers() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -686,9 +689,9 @@ Deno.test(
|
|||
);
|
||||
})();
|
||||
|
||||
const clientConn = await Deno.connect({ port: 4501 });
|
||||
const clientConn = await Deno.connect({ port: listenPort });
|
||||
const requestText =
|
||||
"GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\nX-Header-Test: á\r\n\r\n";
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\nX-Header-Test: á\r\n\r\n`;
|
||||
const requestBytes = new Uint8Array(requestText.length);
|
||||
for (let i = 0; i < requestText.length; i++) {
|
||||
requestBytes[i] = requestText.charCodeAt(i);
|
||||
|
@ -721,7 +724,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerRequestWithoutPath() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
|
@ -729,12 +732,15 @@ Deno.test(
|
|||
const reqEvent = await httpConn.nextRequest();
|
||||
assert(reqEvent);
|
||||
const { request, respondWith } = reqEvent;
|
||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
|
||||
assertEquals(
|
||||
new URL(request.url).href,
|
||||
`http://127.0.0.1:${listenPort}/`,
|
||||
);
|
||||
assertEquals(await request.text(), "");
|
||||
await respondWith(new Response());
|
||||
})();
|
||||
|
||||
const clientConn = await Deno.connect({ port: 4501 });
|
||||
const clientConn = await Deno.connect({ port: listenPort });
|
||||
|
||||
async function writeRequest(conn: Deno.Conn) {
|
||||
const encoder = new TextEncoder();
|
||||
|
@ -742,7 +748,7 @@ Deno.test(
|
|||
const w = new BufWriter(conn);
|
||||
const r = new BufReader(conn);
|
||||
const body =
|
||||
`CONNECT 127.0.0.1:4501 HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
|
||||
`CONNECT 127.0.0.1:${listenPort} HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`;
|
||||
const writeResult = await w.write(encoder.encode(body));
|
||||
assertEquals(body.length, writeResult);
|
||||
await w.flush();
|
||||
|
@ -766,7 +772,7 @@ Deno.test(
|
|||
|
||||
Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
|
@ -786,7 +792,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
|
|||
})();
|
||||
|
||||
const def = deferred();
|
||||
const ws = new WebSocket("ws://localhost:4501");
|
||||
const ws = new WebSocket(`ws://localhost:${listenPort}`);
|
||||
ws.onmessage = (m) => assertEquals(m.data, "foo");
|
||||
ws.onerror = () => fail();
|
||||
ws.onclose = () => def.resolve();
|
||||
|
@ -887,20 +893,23 @@ Deno.test(
|
|||
async function httpCookieConcatenation() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
const reqEvent = await httpConn.nextRequest();
|
||||
assert(reqEvent);
|
||||
const { request, respondWith } = reqEvent;
|
||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
|
||||
assertEquals(
|
||||
new URL(request.url).href,
|
||||
`http://127.0.0.1:${listenPort}/`,
|
||||
);
|
||||
assertEquals(await request.text(), "");
|
||||
assertEquals(request.headers.get("cookie"), "foo=bar; bar=foo");
|
||||
await respondWith(new Response("ok"));
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
headers: [
|
||||
["connection", "close"],
|
||||
["cookie", "foo=bar"],
|
||||
|
@ -916,8 +925,8 @@ Deno.test(
|
|||
|
||||
// https://github.com/denoland/deno/issues/11651
|
||||
Deno.test({ permissions: { net: true } }, async function httpServerPanic() {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const client = await Deno.connect({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const client = await Deno.connect({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
|
||||
|
@ -943,7 +952,7 @@ Deno.test(
|
|||
file.close();
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -952,7 +961,7 @@ Deno.test(
|
|||
const f = await Deno.open(tmpFile, { read: true });
|
||||
await respondWith(new Response(f.readable, { status: 200 }));
|
||||
})();
|
||||
const resp = await fetch("http://127.0.0.1:4501/");
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`);
|
||||
const body = await resp.arrayBuffer();
|
||||
assertEquals(body.byteLength, 70 * 1024);
|
||||
await promise;
|
||||
|
@ -964,9 +973,9 @@ Deno.test(
|
|||
Deno.test(
|
||||
{ permissions: { net: true, write: true, read: true } },
|
||||
async function httpServerClosedStream() {
|
||||
const listener = Deno.listen({ port: 4502 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
|
||||
const client = await Deno.connect({ port: 4502 });
|
||||
const client = await Deno.connect({ port: listenPort });
|
||||
await client.write(new TextEncoder().encode(
|
||||
`GET / HTTP/1.0\r\n\r\n`,
|
||||
));
|
||||
|
@ -1006,9 +1015,9 @@ Deno.test(
|
|||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
async function httpServerIncompleteMessage() {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
|
||||
const client = await Deno.connect({ port: 4501 });
|
||||
const client = await Deno.connect({ port: listenPort });
|
||||
await client.write(new TextEncoder().encode(
|
||||
`GET / HTTP/1.0\r\n\r\n`,
|
||||
));
|
||||
|
@ -1053,17 +1062,17 @@ Deno.test(
|
|||
Deno.test(
|
||||
{ permissions: { net: true } },
|
||||
async function httpServerDoesntLeakResources() {
|
||||
const listener = Deno.listen({ port: 4505 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const [conn, clientConn] = await Promise.all([
|
||||
listener.accept(),
|
||||
Deno.connect({ port: 4505 }),
|
||||
Deno.connect({ port: listenPort }),
|
||||
]);
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
|
||||
await Promise.all([
|
||||
httpConn.nextRequest(),
|
||||
clientConn.write(new TextEncoder().encode(
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:4505\r\n\r\n`,
|
||||
`GET / HTTP/1.1\r\nHost: 127.0.0.1:${listenPort}\r\n\r\n`,
|
||||
)),
|
||||
]);
|
||||
|
||||
|
@ -1081,11 +1090,14 @@ Deno.test(
|
|||
let httpConn: Deno.HttpConn;
|
||||
|
||||
const promise = (async () => {
|
||||
listener = Deno.listen({ port: 4508 });
|
||||
listener = Deno.listen({ port: listenPort });
|
||||
for await (const conn of listener) {
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
for await (const { request, respondWith } of httpConn) {
|
||||
assertEquals(new URL(request.url).href, "http://127.0.0.1:4508/");
|
||||
assertEquals(
|
||||
new URL(request.url).href,
|
||||
`http://127.0.0.1:${listenPort}/`,
|
||||
);
|
||||
// not reading request body on purpose
|
||||
respondWith(new Response("ok"));
|
||||
}
|
||||
|
@ -1093,7 +1105,7 @@ Deno.test(
|
|||
})();
|
||||
|
||||
const resourcesBefore = Deno.resources();
|
||||
const response = await fetch("http://127.0.0.1:4508", {
|
||||
const response = await fetch(`http://127.0.0.1:${listenPort}`, {
|
||||
method: "POST",
|
||||
body: "hello world",
|
||||
});
|
||||
|
@ -1151,7 +1163,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpConnConcurrentNextRequestCalls() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
@ -1189,7 +1201,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpConnAutoCloseDelayedOnUpgrade() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
async function server() {
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
@ -1234,7 +1246,7 @@ Deno.test(
|
|||
{ permissions: { net: true, run: true } },
|
||||
async function httpServerDeleteRequestHasBody() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
@ -1268,7 +1280,7 @@ Deno.test(
|
|||
{ permissions: { net: true } },
|
||||
async function httpServerRespondNonAsciiUint8Array() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
|
@ -1282,7 +1294,7 @@ Deno.test(
|
|||
);
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://localhost:4501/");
|
||||
const resp = await fetch(`http://localhost:${listenPort}/`);
|
||||
assertEquals(resp.status, 200);
|
||||
const body = await resp.arrayBuffer();
|
||||
assertEquals(new Uint8Array(body), new Uint8Array([128]));
|
||||
|
@ -1350,7 +1362,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
||||
const data = { hello: "deno", now: "with", compressed: "body" };
|
||||
|
@ -1402,7 +1414,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
||||
const data = { hello: "deno", now: "with", compressed: "body" };
|
||||
|
@ -1459,7 +1471,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1512,7 +1524,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1568,7 +1580,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1621,7 +1633,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1681,7 +1693,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1740,7 +1752,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1796,7 +1808,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
async function server() {
|
||||
|
@ -1852,7 +1864,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
@ -1914,7 +1926,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
@ -1980,7 +1992,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
let contentLength: string;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
|
@ -2046,7 +2058,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
let contentLength: string;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
|
@ -2108,7 +2120,7 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
let contentLength: string;
|
||||
|
||||
let httpConn: Deno.HttpConn;
|
||||
|
@ -2165,7 +2177,7 @@ Deno.test({
|
|||
|
||||
Deno.test("upgradeHttp tcp", async () => {
|
||||
async function client() {
|
||||
const tcpConn = await Deno.connect({ port: 4501 });
|
||||
const tcpConn = await Deno.connect({ port: listenPort });
|
||||
await tcpConn.write(
|
||||
new TextEncoder().encode(
|
||||
"CONNECT server.example.com:80 HTTP/1.1\r\n\r\nbla bla bla\nbla bla\nbla\n",
|
||||
|
@ -2201,7 +2213,7 @@ Deno.test("upgradeHttp tcp", async () => {
|
|||
})();
|
||||
|
||||
return new Response(null, { status: 101 });
|
||||
}, { port: 4501, signal });
|
||||
}, { port: listenPort, signal });
|
||||
|
||||
await Promise.all([server, client()]);
|
||||
});
|
||||
|
@ -2216,7 +2228,7 @@ Deno.test(
|
|||
];
|
||||
const tlsConn = await Deno.connectTls({
|
||||
hostname: "localhost",
|
||||
port: 4502,
|
||||
port: listenPort,
|
||||
caCerts,
|
||||
});
|
||||
await tlsConn.write(
|
||||
|
@ -2256,7 +2268,7 @@ Deno.test(
|
|||
})();
|
||||
|
||||
return new Response(null, { status: 101 });
|
||||
}, { hostname: "localhost", port: 4502, signal, keyFile, certFile });
|
||||
}, { hostname: "localhost", port: listenPort, signal, keyFile, certFile });
|
||||
|
||||
await Promise.all([server, client()]);
|
||||
},
|
||||
|
@ -2329,7 +2341,7 @@ Deno.test(
|
|||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -2340,7 +2352,7 @@ Deno.test(
|
|||
await respondWith(new Response(body));
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
method: "POST",
|
||||
headers: { "connection": "close" },
|
||||
body,
|
||||
|
@ -2376,7 +2388,7 @@ Deno.test(
|
|||
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -2387,7 +2399,7 @@ Deno.test(
|
|||
await respondWith(new Response(body));
|
||||
})();
|
||||
|
||||
const resp = await fetch("http://127.0.0.1:4501/", {
|
||||
const resp = await fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
method: "POST",
|
||||
headers: { "connection": "close" },
|
||||
body: stream.readable,
|
||||
|
@ -2405,7 +2417,7 @@ Deno.test(
|
|||
permissions: { net: true },
|
||||
},
|
||||
async function httpServerWithoutExclusiveAccessToTcp() {
|
||||
const port = 4506;
|
||||
const port = listenPort;
|
||||
const listener = Deno.listen({ port });
|
||||
|
||||
const [clientConn, serverConn] = await Promise.all([
|
||||
|
@ -2429,7 +2441,7 @@ Deno.test(
|
|||
},
|
||||
async function httpServerWithoutExclusiveAccessToTls() {
|
||||
const hostname = "localhost";
|
||||
const port = 4507;
|
||||
const port = listenPort;
|
||||
const listener = Deno.listenTls({
|
||||
hostname,
|
||||
port,
|
||||
|
@ -2485,7 +2497,7 @@ Deno.test(
|
|||
async function httpServerRequestResponseClone() {
|
||||
const body = "deno".repeat(64 * 1024);
|
||||
let httpConn: Deno.HttpConn;
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const promise = (async () => {
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
|
@ -2524,7 +2536,7 @@ Deno.test(
|
|||
await respondWith(new Response(body));
|
||||
})();
|
||||
|
||||
const response = await fetch("http://localhost:4501", {
|
||||
const response = await fetch(`http://localhost:${listenPort}`, {
|
||||
body,
|
||||
method: "POST",
|
||||
});
|
||||
|
@ -2541,8 +2553,8 @@ Deno.test({
|
|||
permissions: { net: true, run: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port2 = 4502;
|
||||
const port = listenPort;
|
||||
const port2 = listenPort2;
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
|
@ -2674,7 +2686,7 @@ for (const compression of [true, false]) {
|
|||
permissions: { net: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
const server = httpServerWithErrorBody(listener, compression);
|
||||
|
@ -2707,7 +2719,7 @@ for (const compression of [true, false]) {
|
|||
permissions: { net: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
const listener = Deno.listen({ hostname, port });
|
||||
const server = httpServerWithErrorBody(listener, compression);
|
||||
|
@ -2734,7 +2746,7 @@ for (const compression of [true, false]) {
|
|||
permissions: { net: true, read: true },
|
||||
async fn() {
|
||||
const hostname = "localhost";
|
||||
const port = 4501;
|
||||
const port = listenPort;
|
||||
|
||||
const listener = Deno.listenTls({
|
||||
hostname,
|
||||
|
@ -2770,7 +2782,7 @@ Deno.test({
|
|||
async fn() {
|
||||
let httpConn: Deno.HttpConn;
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4501 });
|
||||
const listener = Deno.listen({ port: listenPort });
|
||||
const conn = await listener.accept();
|
||||
listener.close();
|
||||
httpConn = Deno.serveHttp(conn);
|
||||
|
@ -2784,7 +2796,7 @@ Deno.test({
|
|||
|
||||
const abortController = new AbortController();
|
||||
|
||||
fetch("http://127.0.0.1:4501/", {
|
||||
fetch(`http://127.0.0.1:${listenPort}/`, {
|
||||
signal: abortController.signal,
|
||||
}).catch(() => {
|
||||
// ignore
|
||||
|
|
Loading…
Reference in a new issue