Skip to content

Commit 4112c5b

Browse files
authored
bpo-32662: Try making test_asyncio.test_server more reliable (#5338)
1 parent 863b1e4 commit 4112c5b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Lib/test/test_asyncio/test_server.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import asyncio
22
import socket
3+
import time
34
import threading
45
import unittest
56

7+
from test import support
68
from test.test_asyncio import utils as test_utils
79
from test.test_asyncio import functional as func_tests
810

@@ -16,6 +18,14 @@ def test_start_server_1(self):
1618
HELLO_MSG = b'1' * 1024 * 5 + b'\n'
1719

1820
def client(sock, addr):
21+
for i in range(10):
22+
time.sleep(0.2)
23+
if srv.is_serving():
24+
break
25+
else:
26+
raise RuntimeError
27+
28+
sock.settimeout(2)
1929
sock.connect(addr)
2030
sock.send(HELLO_MSG)
2131
sock.recv_all(1)
@@ -33,7 +43,7 @@ async def main(srv):
3343
await srv.serve_forever()
3444

3545
srv = self.loop.run_until_complete(asyncio.start_server(
36-
serve, '127.0.0.1', 0, loop=self.loop, start_serving=False))
46+
serve, support.HOSTv4, 0, loop=self.loop, start_serving=False))
3747

3848
self.assertFalse(srv.is_serving())
3949

@@ -65,6 +75,7 @@ def test_start_unix_server_1(self):
6575
started = threading.Event()
6676

6777
def client(sock, addr):
78+
sock.settimeout(2)
6879
started.wait(5)
6980
sock.connect(addr)
7081
sock.send(HELLO_MSG)

0 commit comments

Comments
 (0)