Skip to content

Commit c326506

Browse files
committed
Make test_remote_shutdown_receives_trailing_data trigger gh-115514
1 parent 9a7be93 commit c326506

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,9 @@ def test_write_buffer_after_close(self):
10581058
# * Protocol has data in its buffer, like SSLProtocol in self._outgoing
10591059
# The data is still written out.
10601060

1061+
# Also tested with real SSL transport in
1062+
# test.test_asyncio.test_ssl.TestSSL.test_remote_shutdown_receives_trailing_data
1063+
10611064
data = memoryview(b'data')
10621065
self.sock.send.return_value = 2
10631066
self.sock.send.fileno.return_value = 7

Lib/test/test_asyncio/test_ssl.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313
import threading
1414
import time
15+
import unittest.mock
1516
import weakref
1617
import unittest
1718

@@ -1410,10 +1411,27 @@ async def client(addr):
14101411
except (BrokenPipeError, ConnectionResetError):
14111412
pass
14121413

1413-
await future
1414-
1415-
writer.close()
1416-
await self.wait_closed(writer)
1414+
# Make sure _SelectorSocketTransport enters the delayed write
1415+
# path in its `write` method by setting the socket buffer to small value,
1416+
# so that `socket.send` does not consume all the data.
1417+
# This triggers bug gh-115514, also tested using mocks in
1418+
# test.test_asyncio.test_selector_events.SelectorSocketTransportTests.test_write_buffer_after_close
1419+
socket_transport = writer.transport._ssl_protocol._transport
1420+
1421+
def _shrink_sock_buffer(data):
1422+
if socket_transport._read_ready_cb is None:
1423+
socket_transport.get_extra_info("socket").setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1)
1424+
return unittest.mock.DEFAULT
1425+
1426+
with unittest.mock.patch.object(
1427+
socket_transport, "write",
1428+
wraps=socket_transport.write,
1429+
side_effect=_shrink_sock_buffer
1430+
):
1431+
await future
1432+
1433+
writer.close()
1434+
await self.wait_closed(writer)
14171435

14181436
def run(meth):
14191437
def wrapper(sock):

0 commit comments

Comments
 (0)