1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 00:21:05 -05:00

fix(std/http): Properly await ops in a server test (#4436)

This commit is contained in:
Nayeem Rahman 2020-03-20 08:46:48 +00:00 committed by GitHub
parent b7e6a31a42
commit 35f6e2e45d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
@ -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();