From fcaf8cd8e37459658a6c06d7e16b3adc9436a135 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 4 Aug 2021 19:45:10 -0400 Subject: [PATCH] chore: refactor `netHangsOnClose` test to not use `deferred` (#11585) --- cli/tests/unit/net_test.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 8b66ff3faa..a7a9454c03 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -551,7 +551,6 @@ unitTest( }, async function netHangsOnClose() { let acceptedConn: Deno.Conn; - const resolvable = deferred(); async function iteratorReq(listener: Deno.Listener): Promise { const p = new Uint8Array(10); @@ -570,21 +569,25 @@ unitTest( assert(!!err); assert(err instanceof Deno.errors.BadResource); } - - resolvable.resolve(); } const addr = { hostname: "127.0.0.1", port: 3500 }; const listener = Deno.listen(addr); - iteratorReq(listener); - const conn = await Deno.connect(addr); - await conn.write(new Uint8Array([1, 2, 3, 4])); - const buf = new Uint8Array(10); - await conn.read(buf); - conn!.close(); - acceptedConn!.close(); - listener.close(); - await resolvable; + const listenerPromise = iteratorReq(listener); + const connectionPromise = (async () => { + const conn = await Deno.connect(addr); + await conn.write(new Uint8Array([1, 2, 3, 4])); + const buf = new Uint8Array(10); + await conn.read(buf); + conn!.close(); + acceptedConn!.close(); + listener.close(); + })(); + + await Promise.all([ + listenerPromise, + connectionPromise, + ]); }, );