Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-32662: Try making test_asyncio.test_server more reliable #5338

Merged
merged 2 commits into from
Jan 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Lib/test/test_asyncio/test_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
import socket
import time
import threading
import unittest

from test import support
from test.test_asyncio import utils as test_utils
from test.test_asyncio import functional as func_tests

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

def client(sock, addr):
for i in range(10):
time.sleep(0.2)
if srv.is_serving():
break
else:
raise RuntimeError

sock.settimeout(2)
sock.connect(addr)
sock.send(HELLO_MSG)
sock.recv_all(1)
Expand All @@ -33,7 +43,7 @@ async def main(srv):
await srv.serve_forever()

srv = self.loop.run_until_complete(asyncio.start_server(
serve, '127.0.0.1', 0, loop=self.loop, start_serving=False))
serve, support.HOSTv4, 0, loop=self.loop, start_serving=False))

self.assertFalse(srv.is_serving())

Expand Down Expand Up @@ -65,6 +75,7 @@ def test_start_unix_server_1(self):
started = threading.Event()

def client(sock, addr):
sock.settimeout(2)
started.wait(5)
sock.connect(addr)
sock.send(HELLO_MSG)
Expand Down