GH-106684: raise ResourceWarning when asyncio.StreamWriter is not closed (#107650)

This commit is contained in:
Kumar Aditya 2023-08-05 17:48:15 +05:30 committed by GitHub
parent 5e2746d6e2
commit 41178e4199
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View file

@ -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()