Skip to content

Commit 1158151

Browse files
committed
Even more deterministic
No possibly infinite loop. Instead ask the system how much buffer space it has and fill that.
1 parent 6c078d6 commit 1158151

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Lib/test/test_asyncio/test_server.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ async def serve(rd, wr):
227227
(c_rd, c_wr) = await asyncio.open_connection(addr[0], addr[1], limit=4096)
228228
self.addCleanup(c_wr.close)
229229

230-
# Limit the send buffer so we can reliably overfill it
230+
# Limit the socket buffers so we can reliably overfill them
231231
s_sock = s_wr.get_extra_info('socket')
232232
s_sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 65536)
233+
c_sock = c_wr.get_extra_info('socket')
234+
c_sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 65536)
233235

234236
# Get the reader in to a paused state by sending more than twice
235237
# the configured limit
@@ -240,10 +242,11 @@ async def serve(rd, wr):
240242
await asyncio.sleep(0)
241243

242244
# Get the writer in a waiting state by sending data until the
243-
# kernel stops accepting more in to the send buffer
244-
while s_wr.transport.get_write_buffer_size() == 0:
245-
s_wr.write(b'a' * 4096)
246-
await asyncio.sleep(0)
245+
# socket buffers are full on both server and client sockets and
246+
# the kernel stops accepting more data
247+
s_wr.write(b'a' * c_sock.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
248+
s_wr.write(b'a' * s_sock.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF))
249+
self.assertNotEqual(s_wr.transport.get_write_buffer_size(), 0)
247250

248251
task = asyncio.create_task(srv.wait_closed())
249252
await asyncio.sleep(0)

0 commit comments

Comments
 (0)