Skip to content

bpo-30064: Fix slow asyncio sock test #20868

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

Merged
merged 1 commit into from
Jun 14, 2020
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
34 changes: 20 additions & 14 deletions Lib/test/test_asyncio/test_sock_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ async def _basetest_sock_send_racing(self, listener, sock):
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()))
Expand All @@ -176,30 +177,35 @@ async def _basetest_sock_send_racing(self, listener, sock):
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(
self.loop.sock_sendall(sock, b'hello'))
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,
Expand Down