diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-04 20:51:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 20:51:53 (GMT) |
commit | 92ba4e10fad21db6505b819738b6d6458cb3f5e7 (patch) | |
tree | 754dac30162a0dc746fda77b2ef2453a6492448c /Lib/test | |
parent | d3f2051eec6039811ae42e4382e8b292a983edc1 (diff) | |
download | cpython-92ba4e10fad21db6505b819738b6d6458cb3f5e7.zip cpython-92ba4e10fad21db6505b819738b6d6458cb3f5e7.tar.gz cpython-92ba4e10fad21db6505b819738b6d6458cb3f5e7.tar.bz2 |
[3.12] gh-113538: Don't error in stream reader protocol callback when task is cancelled (GH-113690) (#113713)
(cherry picked from commit 4681a5271a8598b46021cbc556ac8098ab8a1d81)
Co-authored-by: Guido van Rossum <guido@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncio/test_streams.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index b408cd1..3c8cc5f 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1129,7 +1129,7 @@ os.close(fd) self.assertEqual(messages, []) - def test_unhandled_exceptions(self) -> None: + def _basetest_unhandled_exceptions(self, handle_echo): port = socket_helper.find_unused_port() messages = [] @@ -1143,9 +1143,6 @@ os.close(fd) await wr.wait_closed() async def main(): - async def handle_echo(reader, writer): - raise Exception('test') - server = await asyncio.start_server( handle_echo, 'localhost', port) await server.start_serving() @@ -1154,11 +1151,20 @@ os.close(fd) await server.wait_closed() self.loop.run_until_complete(main()) + return messages + def test_unhandled_exception(self): + async def handle_echo(reader, writer): + raise Exception('test') + messages = self._basetest_unhandled_exceptions(handle_echo) self.assertEqual(messages[0]['message'], - 'Unhandled exception in client_connected_cb') - # Break explicitly reference cycle - messages = None + 'Unhandled exception in client_connected_cb') + + def test_unhandled_cancel(self): + async def handle_echo(reader, writer): + asyncio.current_task().cancel() + messages = self._basetest_unhandled_exceptions(handle_echo) + self.assertEqual(messages, []) if __name__ == '__main__': |