Skip to content

Commit 0e55a4e

Browse files
committed
Add test for _FlowControlMixin pause_writing exception handling
1 parent 43c60ec commit 0e55a4e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/test/test_asyncio/test_transports.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ def get_write_buffer_size(self):
9898
self.assertTrue(transport._protocol_paused)
9999
self.assertEqual(transport.get_write_buffer_limits(), (128, 256))
100100

101+
def test_flowcontrol_mixin_pause_writing_exception(self):
102+
103+
class MyTransport(transports._FlowControlMixin,
104+
transports.Transport):
105+
106+
def get_write_buffer_size(self):
107+
return 2000
108+
109+
loop = mock.Mock()
110+
transport = MyTransport(loop=loop)
111+
protocol = mock.Mock()
112+
protocol.pause_writing.side_effect = RuntimeError("boom")
113+
transport._protocol = protocol
114+
transport.set_write_buffer_limits(high=1000, low=100)
115+
transport._maybe_pause_protocol()
116+
protocol.pause_writing.assert_called_once()
117+
loop.call_exception_handler.assert_called_once()
118+
args = loop.call_exception_handler.call_args[0][0]
119+
120+
self.assertIn("protocol.pause_writing() failed", args["message"])
121+
self.assertIsInstance(args["exception"], RuntimeError)
122+
self.assertTrue(transport._protocol_paused)
123+
101124
def test_flowcontrol_mixin_compute_write_limits(self):
102125

103126
class MyTransport(transports._FlowControlMixin,

0 commit comments

Comments
 (0)