diff options
Diffstat (limited to 'cli/tests/unit/net_test.ts')
-rw-r--r-- | cli/tests/unit/net_test.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 7ea1b8bcf..7efc7e689 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -308,6 +308,44 @@ Deno.test( Deno.test( { permissions: { net: true } }, + async function netUdpSendReceiveBroadcast() { + // Must bind sender to an address that can send to the broadcast address on MacOS. + // Macos will give us error 49 when sending the broadcast packet if we omit hostname here. + const alice = Deno.listenDatagram({ + port: 3500, + transport: "udp", + hostname: "0.0.0.0", + }); + + const bob = Deno.listenDatagram({ + port: 4501, + transport: "udp", + hostname: "0.0.0.0", + }); + assert(bob.addr.transport === "udp"); + assertEquals(bob.addr.port, 4501); + assertEquals(bob.addr.hostname, "0.0.0.0"); + + const broadcastAddr = { ...bob.addr, hostname: "255.255.255.255" }; + + const sent = new Uint8Array([1, 2, 3]); + const byteLength = await alice.send(sent, broadcastAddr); + + assertEquals(byteLength, 3); + const [recvd, remote] = await bob.receive(); + assert(remote.transport === "udp"); + assertEquals(remote.port, 3500); + assertEquals(recvd.length, 3); + assertEquals(1, recvd[0]); + assertEquals(2, recvd[1]); + assertEquals(3, recvd[2]); + alice.close(); + bob.close(); + }, +); + +Deno.test( + { permissions: { net: true } }, async function netUdpConcurrentSendReceive() { const socket = Deno.listenDatagram({ port: 3500, transport: "udp" }); assert(socket.addr.transport === "udp"); |