File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import socket
3
3
import unittest
4
+ from tempfile import mktemp
4
5
5
6
from uvloop import _testbase as tb
6
7
@@ -180,3 +181,37 @@ async def run():
180
181
181
182
class Test_AIO_DNS (BaseTestDNS , tb .AIOTestCase ):
182
183
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
You can’t perform that action at this time.
0 commit comments