diff --git a/tests/test_tcp.py b/tests/test_tcp.py index 73ff43b..6f2602e 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -1,5 +1,5 @@ import asyncio -import logging +import gc import socket import unittest.mock import uvloop @@ -584,6 +584,42 @@ class Test_UV_TCP(_TestTCP, tb.UVTestCase): self.loop.run_until_complete(run()) + def test_tcp_handle_unclosed_gc(self): + fut = self.loop.create_future() + + async def server(reader, writer): + writer.transport.abort() + fut.set_result(True) + + async def run(): + addr = srv.sockets[0].getsockname() + await asyncio.open_connection(*addr, loop=self.loop) + await fut + srv.close() + await srv.wait_closed() + + srv = self.loop.run_until_complete(asyncio.start_server( + server, + '127.0.0.1', 0, + family=socket.AF_INET, + loop=self.loop)) + + if self.loop.get_debug(): + rx = r'unclosed resource self + if self._loop._debug: + self._source_traceback = tb_extract_stack(sys_getframe(0)) cdef inline _start_init(self, Loop loop): IF DEBUG: @@ -322,5 +334,5 @@ cdef void __uv_walk_close_all_handles_cb(uv.uv_handle_t* handle, void* arg) with h = handle.data if not h._closed: - warnings_warn("unclosed resource {!r}".format(h), ResourceWarning) + h._warn_unclosed() h._close()