From d06c95637a2a19588fcb549ed7b760a916b3cbfd Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Thu, 17 Jan 2019 15:10:34 -0800 Subject: [PATCH] Unflake test netConcurrentAccept (#1544) --- js/net_test.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/js/net_test.ts b/js/net_test.ts index be415f19c7..8eaa95e62e 100644 --- a/js/net_test.ts +++ b/js/net_test.ts @@ -25,23 +25,23 @@ testPerm({ net: true }, async function netCloseWhileAccept() { testPerm({ net: true }, async function netConcurrentAccept() { const listener = deno.listen("tcp", ":4502"); - let err; - // Consume this accept error - // (since it would still be waiting when listener.close is called) - listener.accept().catch(e => { + let acceptErrCount = 0; + const checkErr = e => { assertEqual(e.kind, deno.ErrorKind.Other); - assertEqual(e.message, "Listener has been closed"); - }); - const p1 = listener.accept(); - try { - await p1; - } catch (e) { - err = e; - } - assert(!!err); - assertEqual(err.kind, deno.ErrorKind.Other); - assertEqual(err.message, "Another accept task is ongoing"); + if (e.message === "Listener has been closed") { + assertEqual(acceptErrCount, 1); + } else if (e.message === "Another accept task is ongoing") { + acceptErrCount++; + } else { + throw new Error("Unexpected error message"); + } + }; + const p = listener.accept().catch(checkErr); + const p1 = listener.accept().catch(checkErr); + await Promise.race([p, p1]); listener.close(); + await [p, p1]; + assertEqual(acceptErrCount, 1); }); testPerm({ net: true }, async function netDialListen() {