summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-08-29 09:44:54 (GMT)
committerGitHub <noreply@github.com>2024-08-29 09:44:54 (GMT)
commitada13a82a886499ba690902bf5b93b50ace77220 (patch)
tree3de7e00fe651aa56e247a613b775d4e1f7fb18fd
parentbd29ce850907e6e1b0c4b99e97b94061fb865fa4 (diff)
downloadcpython-ada13a82a886499ba690902bf5b93b50ace77220.zip
cpython-ada13a82a886499ba690902bf5b93b50ace77220.tar.gz
cpython-ada13a82a886499ba690902bf5b93b50ace77220.tar.bz2
[3.13] gh-122136: test_asyncio: Don't fail if the kernel buffers more data than advertised (GH-123423) (#123443)
gh-122136: test_asyncio: Don't fail if the kernel buffers more data than advertised (GH-123423) (cherry picked from commit b379f1b26c1e89c8e9160b4dede61b980cc77be6) Co-authored-by: Petr Viktorin <encukou@gmail.com>
-rw-r--r--Lib/test/test_asyncio/test_server.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/test/test_asyncio/test_server.py b/Lib/test/test_asyncio/test_server.py
index 4ca8a16..60a40cc 100644
--- a/Lib/test/test_asyncio/test_server.py
+++ b/Lib/test/test_asyncio/test_server.py
@@ -227,7 +227,7 @@ class TestServer2(unittest.IsolatedAsyncioTestCase):
(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')
@@ -242,10 +242,18 @@ class TestServer2(unittest.IsolatedAsyncioTestCase):
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())