Skip to content

Commit

Permalink
refactor(ext/http): rewrite hyper integration and fix bug (denoland#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Nov 8, 2021
1 parent f1b1a3f commit 5b1e537
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 616 deletions.
40 changes: 39 additions & 1 deletion cli/tests/unit/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
assert,
assertEquals,
assertRejects,
assertStrictEquals,
assertThrows,
deferred,
delay,
Expand Down Expand Up @@ -386,7 +387,7 @@ unitTest(
Deno.errors.Http,
"connection closed",
);
// The error from `op_http_request_next` reroutes to `respondWith()`.
// The error from `op_http_accept` reroutes to `respondWith()`.
assertEquals(await nextRequestPromise, null);
listener.close();
})();
Expand Down Expand Up @@ -865,6 +866,7 @@ unitTest(
const writer = writable.getWriter();

async function writeResponse() {
await delay(50);
await writer.write(
new TextEncoder().encode(
"written to the writable side of a TransformStream",
Expand Down Expand Up @@ -999,3 +1001,39 @@ unitTest(
await Promise.all([server(), client()]);
},
);

// https://github.com/denoland/deno/pull/12332
unitTest(
{ permissions: { net: true } },
async function httpConnConcurrentNextRequestCalls() {
const hostname = "localhost";
const port = 4501;

async function server() {
const listener = Deno.listen({ hostname, port });
const tcpConn = await listener.accept();
const httpConn = Deno.serveHttp(tcpConn);
const promises = new Array(10).fill(null).map(async (_, i) => {
const event = await httpConn.nextRequest();
assert(event);
const { pathname } = new URL(event.request.url);
assertStrictEquals(pathname, `/${i}`);
const response = new Response(`Response #${i}`);
await event.respondWith(response);
});
await Promise.all(promises);
httpConn.close();
listener.close();
}

async function client() {
for (let i = 0; i < 10; i++) {
const response = await fetch(`http:https://${hostname}:${port}/${i}`);
const body = await response.text();
assertStrictEquals(body, `Response #${i}`);
}
}

await Promise.all([server(), delay(100).then(client)]);
},
);
Loading

0 comments on commit 5b1e537

Please sign in to comment.