Skip to content

Commit 3d0324a

Browse files
committed
[fix] test for MagicStack#269
1 parent 6b91061 commit 3d0324a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_dns.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import socket
33
import unittest
4+
from tempfile import mktemp
45

56
from uvloop import _testbase as tb
67

@@ -180,3 +181,37 @@ async def run():
180181

181182
class Test_AIO_DNS(BaseTestDNS, tb.AIOTestCase):
182183
pass
184+
185+
186+
class TestUnixUDPServer(tb.UVTestCase):
187+
def test_unix_socket(self):
188+
class UDPProtocol:
189+
packets = []
190+
event = None
191+
192+
def connection_made(self, transport):
193+
self.transport = transport
194+
195+
def connection_lost(self, transport):
196+
pass
197+
198+
def datagram_received(self, data, addr):
199+
self.packets.append((data, addr))
200+
self.event.set()
201+
202+
with socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) as sock:
203+
sock_path = mktemp(suffix='.sock')
204+
sock.bind(sock_path)
205+
206+
async def run():
207+
transport, protocol = await self.loop.create_datagram_endpoint(
208+
UDPProtocol, sock=sock
209+
)
210+
211+
UDPProtocol.event = asyncio.Event(loop=self.loop)
212+
transport.sendto(b'Hello', sock_path)
213+
await asyncio.wait_for(UDPProtocol.event.wait(), timeout=2)
214+
transport.close()
215+
216+
self.loop.run_until_complete(run())
217+
assert UDPProtocol.packets

0 commit comments

Comments
 (0)