summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_streams.py
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2023-08-05 12:18:15 (GMT)
committerGitHub <noreply@github.com>2023-08-05 12:18:15 (GMT)
commit41178e41995992bbe417f94bce158de93f9e3188 (patch)
tree9922689458e6446a82e0f2ad067a543ccf7e3ff3 /Lib/test/test_asyncio/test_streams.py
parent5e2746d6e2fb0da29225ead7135f078c5f087b57 (diff)
downloadcpython-41178e41995992bbe417f94bce158de93f9e3188.zip
cpython-41178e41995992bbe417f94bce158de93f9e3188.tar.gz
cpython-41178e41995992bbe417f94bce158de93f9e3188.tar.bz2
GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (#107650)
Diffstat (limited to 'Lib/test/test_asyncio/test_streams.py')
-rw-r--r--Lib/test/test_asyncio/test_streams.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 7f9dc62..9c92e75 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -1074,6 +1074,29 @@ os.close(fd)
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):
+ del wr
+ gc.collect()
+
+
+ messages = []
+ self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
+
+ with test_utils.run_test_server() as httpd:
+ self.loop.run_until_complete(inner(httpd))
+
+ self.assertEqual(messages, [])
+
+
if __name__ == '__main__':
unittest.main()