File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,23 @@ async def test_listen(service_binary):
4343 str (port ),
4444 stdout = asyncio .subprocess .PIPE ,
4545 )
46- await asyncio .sleep (0.3 ) # give time to open listening socket
4746
48- with socket .socket (socket .AF_INET6 , socket .SOCK_STREAM ) as client :
49- client .connect (('localhost' , port ))
47+ # try several times to make sure netcat has opened the tcp port
48+ for i in range (1 , 100 ):
49+ try :
50+ client = socket .socket (socket .AF_INET6 , socket .SOCK_STREAM )
51+ client .connect (('localhost' , port ))
52+ break
53+ except ConnectionRefusedError :
54+ if client :
55+ client .close ()
56+ client = None
57+ await asyncio .sleep (0.3 )
58+ continue
59+ else :
60+ assert False , 'failed to connect to netcat'
61+
62+ try :
5063 client .setblocking (False )
5164
5265 loop = asyncio .get_event_loop ()
@@ -57,3 +70,5 @@ async def test_listen(service_binary):
5770
5871 subprocess .terminate ()
5972 await subprocess .wait ()
73+ finally :
74+ client .close ()
You can’t perform that action at this time.
0 commit comments