Skip to content

Commit

Permalink
fix(std/http): Properly await ops in a server test (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Mar 20, 2020
1 parent b7e6a31 commit 35f6e2e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions std/http/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,12 @@ test({
async fn(): Promise<void> {
async function iteratorReq(server: Server): Promise<void> {
for await (const req of server) {
req.respond({ body: new TextEncoder().encode(req.url) });
await req.respond({ body: new TextEncoder().encode(req.url) });
}
}

const server = serve(":8123");
iteratorReq(server);
const p = iteratorReq(server);
const conn = await Deno.connect({ hostname: "127.0.0.1", port: 8123 });
await Deno.writeAll(
conn,
Expand All @@ -479,8 +479,7 @@ test({
const resStr = new TextDecoder().decode(res.subarray(0, nread));
assertStrContains(resStr, "/hello");
server.close();
// Defer to allow async ops to resolve after server has been closed.
await delay(0);
await p;
// Client connection should still be open, verify that
// it's visible in resource table.
const resources = Deno.resources();
Expand Down

0 comments on commit 35f6e2e

Please sign in to comment.