diff options
Diffstat (limited to 'cli/tests/unit/net_test.ts')
| -rw-r--r-- | cli/tests/unit/net_test.ts | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 10fed0c47..eeaada05e 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -9,6 +9,7 @@ import { delay, execCode, } from "./test_util.ts"; +import { join } from "../../../test_util/std/path/mod.ts"; let isCI: boolean; try { @@ -43,13 +44,18 @@ Deno.test( }, ); +function tmpUnixSocketPath(): string { + const folder = Deno.makeTempDirSync(); + return join(folder, "socket"); +} + Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, }, function netUnixListenClose() { - const filePath = Deno.makeTempFileSync(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listen({ path: filePath, transport: "unix", @@ -66,7 +72,7 @@ Deno.test( permissions: { read: true, write: true }, }, function netUnixPacketListenClose() { - const filePath = Deno.makeTempFileSync(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listenDatagram({ path: filePath, transport: "unixpacket", @@ -84,7 +90,7 @@ Deno.test( }, function netUnixListenWritePermission() { assertThrows(() => { - const filePath = Deno.makeTempFileSync(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listen({ path: filePath, transport: "unix", @@ -103,7 +109,7 @@ Deno.test( }, function netUnixPacketListenWritePermission() { assertThrows(() => { - const filePath = Deno.makeTempFileSync(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listenDatagram({ path: filePath, transport: "unixpacket", @@ -139,7 +145,7 @@ Deno.test( permissions: { read: true, write: true }, }, async function netUnixCloseWhileAccept() { - const filePath = await Deno.makeTempFile(); + const filePath = tmpUnixSocketPath(); const listener = Deno.listen({ path: filePath, transport: "unix", @@ -183,7 +189,7 @@ Deno.test( permissions: { read: true, write: true }, }, async function netUnixConcurrentAccept() { - const filePath = await Deno.makeTempFile(); + const filePath = tmpUnixSocketPath(); const listener = Deno.listen({ transport: "unix", path: filePath }); let acceptErrCount = 0; const checkErr = (e: Error) => { @@ -317,7 +323,7 @@ Deno.test( permissions: { read: true, write: true }, }, async function netUnixDialListen() { - const filePath = await Deno.makeTempFile(); + const filePath = tmpUnixSocketPath(); const listener = Deno.listen({ path: filePath, transport: "unix" }); listener.accept().then( async (conn) => { @@ -463,20 +469,21 @@ Deno.test( permissions: { read: true, write: true }, }, async function netUnixPacketSendReceive() { - const filePath = await Deno.makeTempFile(); + const aliceFilePath = tmpUnixSocketPath(); const alice = Deno.listenDatagram({ - path: filePath, + path: aliceFilePath, transport: "unixpacket", }); assert(alice.addr.transport === "unixpacket"); - assertEquals(alice.addr.path, filePath); + assertEquals(alice.addr.path, aliceFilePath); + const bobFilePath = tmpUnixSocketPath(); const bob = Deno.listenDatagram({ - path: filePath, + path: bobFilePath, transport: "unixpacket", }); assert(bob.addr.transport === "unixpacket"); - assertEquals(bob.addr.path, filePath); + assertEquals(bob.addr.path, bobFilePath); const sent = new Uint8Array([1, 2, 3]); const byteLength = await alice.send(sent, bob.addr); @@ -484,7 +491,7 @@ Deno.test( const [recvd, remote] = await bob.receive(); assert(remote.transport === "unixpacket"); - assertEquals(remote.path, filePath); + assertEquals(remote.path, aliceFilePath); assertEquals(recvd.length, 3); assertEquals(1, recvd[0]); assertEquals(2, recvd[1]); @@ -494,11 +501,11 @@ Deno.test( }, ); -// TODO(piscisaureus): Enable after Tokio v0.3/v1.0 upgrade. +// TODO(lucacasonato): support concurrent reads and writes on unixpacket sockets Deno.test( { ignore: true, permissions: { read: true, write: true } }, async function netUnixPacketConcurrentSendReceive() { - const filePath = await Deno.makeTempFile(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listenDatagram({ path: filePath, transport: "unixpacket", @@ -584,7 +591,7 @@ Deno.test( permissions: { read: true, write: true }, }, async function netUnixListenCloseWhileIterating() { - const filePath = Deno.makeTempFileSync(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listen({ path: filePath, transport: "unix" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); socket.close(); @@ -601,7 +608,7 @@ Deno.test( permissions: { read: true, write: true }, }, async function netUnixPacketListenCloseWhileIterating() { - const filePath = Deno.makeTempFileSync(); + const filePath = tmpUnixSocketPath(); const socket = Deno.listenDatagram({ path: filePath, transport: "unixpacket", @@ -884,3 +891,18 @@ Deno.test( clearTimeout(timer); }, ); + +Deno.test({ + ignore: Deno.build.os === "windows", + permissions: { read: true, write: true }, +}, function netUnixListenAddrAlreadyInUse() { + const filePath = tmpUnixSocketPath(); + const listener = Deno.listen({ path: filePath, transport: "unix" }); + assertThrows( + () => { + Deno.listen({ path: filePath, transport: "unix" }); + }, + Deno.errors.AddrInUse, + ); + listener.close(); +}); |
