diff options
author | Kumar Aditya <kumaraditya@python.org> | 2023-11-02 08:18:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 08:18:49 (GMT) |
commit | 9aa88290d82e2808eed84e7a63d0bf9623f84f53 (patch) | |
tree | 16998db48c9582155cb69b515c3f31c4e29199a8 /Lib/test/test_asyncio/test_streams.py | |
parent | 99f0dd88b1ef8309a4e2a23a51bb47e18e1d81f3 (diff) | |
download | cpython-9aa88290d82e2808eed84e7a63d0bf9623f84f53.zip cpython-9aa88290d82e2808eed84e7a63d0bf9623f84f53.tar.gz cpython-9aa88290d82e2808eed84e7a63d0bf9623f84f53.tar.bz2 |
[3.12] GH-110894: Call loop exception handler for exceptions in client_connected_cb (GH-111601) (#111632)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it..
(cherry picked from commit 229f44d353c71185414a072017f46f125676bdd6)
Diffstat (limited to 'Lib/test/test_asyncio/test_streams.py')
-rw-r--r-- | Lib/test/test_asyncio/test_streams.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index 7f9dc62..a0ed5ab 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1074,6 +1074,35 @@ os.close(fd) self.assertEqual(messages, []) + def test_unhandled_exceptions(self) -> None: + port = socket_helper.find_unused_port() + + messages = [] + self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx)) + + async def client(): + rd, wr = await asyncio.open_connection('localhost', port) + wr.write(b'test msg') + await wr.drain() + wr.close() + 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() + await client() + server.close() + await server.wait_closed() + + self.loop.run_until_complete(main()) + + self.assertEqual(messages[0]['message'], + 'Unhandled exception in client_connected_cb') + if __name__ == '__main__': unittest.main() |