diff options
author | Guido van Rossum <guido@python.org> | 2024-01-04 12:20:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 12:20:21 -0800 |
commit | 4681a5271a8598b46021cbc556ac8098ab8a1d81 (patch) | |
tree | 56b7bcaaf0ae3ce4ef3346ff1bb4c7d5728063f3 /Lib/test/test_asyncio/test_streams.py | |
parent | 1600d78e2d090319930c6538b496ffcca120a696 (diff) | |
download | cpython-4681a5271a8598b46021cbc556ac8098ab8a1d81.tar.gz cpython-4681a5271a8598b46021cbc556ac8098ab8a1d81.zip |
gh-113538: Don't error in stream reader protocol callback when task is cancelled (#113690)
Diffstat (limited to 'Lib/test/test_asyncio/test_streams.py')
-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 b408cd1f7da..3c8cc5f3649 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__': |