From 5f3cbff10eead21376bb195688ced6f4e360b134 Mon Sep 17 00:00:00 2001 From: DPR Date: Sun, 19 Nov 2023 11:21:34 +0800 Subject: [PATCH] gh-112186: Improve test case `test_loop_is_closed_resource_warnings` (#112187) (cherry picked from commit 18c692946953e586db432fd06c856531a2b05127) --- Lib/test/test_asyncio/test_streams.py | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index 86354306f1fff3..f5decbe53dacb3 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1067,6 +1067,62 @@ def test_eof_feed_when_closing_writer(self): self.assertEqual(messages, []) + def test_unclosed_resource_warnings(self): + async def inner(httpd): + rd, wr = await asyncio.open_connection(*httpd.address) + + wr.write(b'GET / HTTP/1.0\r\n\r\n') + data = await rd.readline() + self.assertEqual(data, b'HTTP/1.0 200 OK\r\n') + data = await rd.read() + self.assertTrue(data.endswith(b'\r\n\r\nTest message')) + with self.assertWarns(ResourceWarning) as cm: + del wr + gc.collect() + self.assertEqual(len(cm.warnings), 1) + self.assertTrue(str(cm.warnings[0].message).startswith("unclosed None: port = socket_helper.find_unused_port()