1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

chore: refactor netHangsOnClose test to not use deferred (#11585)

This commit is contained in:
David Sherret 2021-08-04 19:45:10 -04:00 committed by GitHub
parent 87de8e82a1
commit fcaf8cd8e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -551,7 +551,6 @@ unitTest(
},
async function netHangsOnClose() {
let acceptedConn: Deno.Conn;
const resolvable = deferred();
async function iteratorReq(listener: Deno.Listener): Promise<void> {
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,
]);
},
);