summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-14 08:08:08 (GMT)
committerGitHub <noreply@github.com>2020-06-14 08:08:08 (GMT)
commit83cd968f5cc59ad60b665080087f50fefac17a07 (patch)
treed4df54e06fe7c4692f27537757340592984940b9
parent37c9fc5baa29d28c6809807b8f06444126760928 (diff)
downloadcpython-83cd968f5cc59ad60b665080087f50fefac17a07.zip
cpython-83cd968f5cc59ad60b665080087f50fefac17a07.tar.gz
cpython-83cd968f5cc59ad60b665080087f50fefac17a07.tar.bz2
bpo-30064: Fix slow asyncio sock test (GH-20868)
Using a log2n way to fill a much smaller buffer, and receiving in a cleaner way with EOF. The failing test was reproducible using the following command thanks to @aeros : ```bash ./python -m test test_asyncio.test_sock_lowlevel --match test_sock_client_racing -j100 -F -v ``` According to test results, we may still need to bump the timeout: https://github.com/python/cpython/blob/5aad027db9618f22f6fa2274e05dd50f928d2ed7/Lib/test/test_asyncio/test_sock_lowlevel.pyGH-L256-L257 (cherry picked from commit 8f04a84755babe516ebb5304904ea7c15b865c80) Co-authored-by: Fantix King <fantix.king@gmail.com>
-rw-r--r--Lib/test/test_asyncio/test_sock_lowlevel.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py
index 2c8ce6b..e339ee9 100644
--- a/Lib/test/test_asyncio/test_sock_lowlevel.py
+++ b/Lib/test/test_asyncio/test_sock_lowlevel.py
@@ -166,6 +166,7 @@ class BaseSockTestsMixin:
listener.listen(1)
# make connection
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
sock.setblocking(False)
task = asyncio.create_task(
self.loop.sock_connect(sock, listener.getsockname()))
@@ -176,10 +177,13 @@ class BaseSockTestsMixin:
with server:
await task
- # fill the buffer
- with self.assertRaises(BlockingIOError):
- while True:
- sock.send(b' ' * 5)
+ # fill the buffer until sending 5 chars would block
+ size = 8192
+ while size >= 4:
+ with self.assertRaises(BlockingIOError):
+ while True:
+ sock.send(b' ' * size)
+ size = int(size / 2)
# cancel a blocked sock_sendall
task = asyncio.create_task(
@@ -187,19 +191,21 @@ class BaseSockTestsMixin:
await asyncio.sleep(0)
task.cancel()
- # clear the buffer
- async def recv_until():
- data = b''
- while not data:
- data = await self.loop.sock_recv(server, 1024)
- data = data.strip()
- return data
- task = asyncio.create_task(recv_until())
+ # receive everything that is not a space
+ async def recv_all():
+ rv = b''
+ while True:
+ buf = await self.loop.sock_recv(server, 8192)
+ if not buf:
+ return rv
+ rv += buf.strip()
+ task = asyncio.create_task(recv_all())
- # immediately register another sock_sendall
+ # immediately make another sock_sendall call
await self.loop.sock_sendall(sock, b'world')
+ sock.shutdown(socket.SHUT_WR)
data = await task
- # ProactorEventLoop could deliver hello
+ # ProactorEventLoop could deliver hello, so endswith is necessary
self.assertTrue(data.endswith(b'world'))
# After the first connect attempt before the listener is ready,