@@ -96,10 +96,18 @@ async def start_server():
9696
9797 self .assertFalse (srv .is_serving ())
9898
99- # asyncio doesn't cleanup the sock file
100- self .assertTrue (os .path .exists (sock_name ))
99+ if sys .version_info < (3 , 13 ):
100+ # asyncio doesn't cleanup the sock file under Python 3.13
101+ self .assertTrue (os .path .exists (sock_name ))
102+ else :
103+ self .assertFalse (os .path .exists (sock_name ))
104+
105+ async def start_server_sock (start_server , is_unix_api = True ):
106+ # is_unix_api indicates whether `start_server` is calling
107+ # `loop.create_unix_server()` or `loop.create_server()`,
108+ # because asyncio `loop.create_server()` doesn't cleanup
109+ # the socket file even if it's a UNIX socket.
101110
102- async def start_server_sock (start_server ):
103111 nonlocal CNT
104112 CNT = 0
105113
@@ -140,8 +148,11 @@ async def start_server_sock(start_server):
140148
141149 self .assertFalse (srv .is_serving ())
142150
143- # asyncio doesn't cleanup the sock file
144- self .assertTrue (os .path .exists (sock_name ))
151+ if sys .version_info < (3 , 13 ) or not is_unix_api :
152+ # asyncio doesn't cleanup the sock file under Python 3.13
153+ self .assertTrue (os .path .exists (sock_name ))
154+ else :
155+ self .assertFalse (os .path .exists (sock_name ))
145156
146157 with self .subTest (func = 'start_unix_server(host, port)' ):
147158 self .loop .run_until_complete (start_server ())
@@ -160,7 +171,7 @@ async def start_server_sock(start_server):
160171 lambda sock : asyncio .start_server (
161172 handle_client ,
162173 None , None ,
163- sock = sock )))
174+ sock = sock ), is_unix_api = False ))
164175 self .assertEqual (CNT , TOTAL_CNT )
165176
166177 def test_create_unix_server_2 (self ):
@@ -455,16 +466,13 @@ def test_create_unix_server_path_stream_bittype(self):
455466 socket .AF_UNIX , socket .SOCK_STREAM | socket .SOCK_NONBLOCK )
456467 with tempfile .NamedTemporaryFile () as file :
457468 fn = file .name
458- try :
459- with sock :
460- sock .bind (fn )
461- coro = self .loop .create_unix_server (lambda : None , path = None ,
462- sock = sock )
463- srv = self .loop .run_until_complete (coro )
464- srv .close ()
465- self .loop .run_until_complete (srv .wait_closed ())
466- finally :
467- os .unlink (fn )
469+ with sock :
470+ sock .bind (fn )
471+ coro = self .loop .create_unix_server (lambda : None , path = None ,
472+ sock = sock , cleanup_socket = True )
473+ srv = self .loop .run_until_complete (coro )
474+ srv .close ()
475+ self .loop .run_until_complete (srv .wait_closed ())
468476
469477 @unittest .skipUnless (sys .platform .startswith ('linux' ), 'requires epoll' )
470478 def test_epollhup (self ):
0 commit comments