FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-122136: test_asyncio: Don't fail if the kernel buffers more data than advertised by encukou · Pull Request #123423 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 13 additions & 5 deletions Lib/test/test_asyncio/test_server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async def serve(rd, wr):

(s_rd, s_wr) = await fut

# Limit the socket buffers so we can reliably overfill them
# Limit the socket buffers so we can more reliably overfill them
s_sock = s_wr.get_extra_info('socket')
s_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)
c_sock = c_wr.get_extra_info('socket')
Expand All @@ -242,10 +242,18 @@ async def serve(rd, wr):
await asyncio.sleep(0)

# Get the writer in a waiting state by sending data until the
# socket buffers are full on both server and client sockets and
# the kernel stops accepting more data
s_wr.write(b'a' * c_sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
s_wr.write(b'a' * s_sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF))
# kernel stops accepting more data in the send buffer.
# gh-122136: getsockopt() does not reliably report the buffer size
# available for message content.
# We loop until we start filling up the asyncio buffer.
# To avoid an infinite loop we cap at 10 times the expected value
c_bufsize = c_sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
s_bufsize = s_sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
for i in range(10):
s_wr.write(b'a' * c_bufsize)
s_wr.write(b'a' * s_bufsize)
if s_wr.transport.get_write_buffer_size() > 0:
break
self.assertNotEqual(s_wr.transport.get_write_buffer_size(), 0)

task = asyncio.create_task(srv.wait_closed())
Expand Down

Back | FazBrowse Home | New Git URL