From f4b57143fe009644d170879e562fb230dca4c461 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 26 Jan 2018 00:37:23 -0500 Subject: [PATCH 1/2] bpo-32662: Try making test_asyncio.test_server more reliable --- Lib/test/test_asyncio/test_server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_server.py b/Lib/test/test_asyncio/test_server.py index 44d135db10576f..68e862f5cd08b6 100644 --- a/Lib/test/test_asyncio/test_server.py +++ b/Lib/test/test_asyncio/test_server.py @@ -1,5 +1,6 @@ import asyncio import socket +import time import threading import unittest @@ -16,6 +17,8 @@ def test_start_server_1(self): HELLO_MSG = b'1' * 1024 * 5 + b'\n' def client(sock, addr): + time.sleep(0.2) + sock.settimeout(2) sock.connect(addr) sock.send(HELLO_MSG) sock.recv_all(1) @@ -33,7 +36,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, '0.0.0.0', 0, loop=self.loop, start_serving=False)) self.assertFalse(srv.is_serving()) @@ -65,6 +68,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) From a1ae2a70dfb8ec0dbdb8eb6e7e3675c996149fff Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 26 Jan 2018 01:10:11 -0500 Subject: [PATCH 2/2] Another set of fixes --- Lib/test/test_asyncio/test_server.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_asyncio/test_server.py b/Lib/test/test_asyncio/test_server.py index 68e862f5cd08b6..034293cb3f5961 100644 --- a/Lib/test/test_asyncio/test_server.py +++ b/Lib/test/test_asyncio/test_server.py @@ -4,6 +4,7 @@ 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 @@ -17,7 +18,13 @@ def test_start_server_1(self): HELLO_MSG = b'1' * 1024 * 5 + b'\n' def client(sock, addr): - time.sleep(0.2) + 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) @@ -36,7 +43,7 @@ async def main(srv): await srv.serve_forever() srv = self.loop.run_until_complete(asyncio.start_server( - serve, '0.0.0.0', 0, loop=self.loop, start_serving=False)) + serve, support.HOSTv4, 0, loop=self.loop, start_serving=False)) self.assertFalse(srv.is_serving())