Skip to content

Commit

Permalink
Unflake test netConcurrentAccept (denoland#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo authored and ry committed Jan 17, 2019
1 parent d787713 commit d06c956
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions js/net_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d06c956

Please sign in to comment.