Skip to content

gh-113879: Fix ResourceWarning in test_asyncio.test_server #113881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Lib/test/test_asyncio/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ async def test_unix_server_sock_cleanup(self):
async def serve(*args):
pass

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(addr)
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.bind(addr)

srv = await asyncio.start_unix_server(serve, sock=sock)
srv = await asyncio.start_unix_server(serve, sock=sock)

srv.close()
self.assertFalse(os.path.exists(addr))
srv.close()
self.assertFalse(os.path.exists(addr))

@socket_helper.skip_unless_bind_unix_socket
async def test_unix_server_cleanup_gone(self):
Expand All @@ -215,14 +215,14 @@ async def test_unix_server_cleanup_gone(self):
async def serve(*args):
pass

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(addr)
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.bind(addr)

srv = await asyncio.start_unix_server(serve, sock=sock)
srv = await asyncio.start_unix_server(serve, sock=sock)

os.unlink(addr)
os.unlink(addr)

srv.close()
srv.close()

@socket_helper.skip_unless_bind_unix_socket
async def test_unix_server_cleanup_replaced(self):
Expand All @@ -234,11 +234,11 @@ async def serve(*args):
srv = await asyncio.start_unix_server(serve, addr)

os.unlink(addr)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(addr)
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.bind(addr)

srv.close()
self.assertTrue(os.path.exists(addr))
srv.close()
self.assertTrue(os.path.exists(addr))

@socket_helper.skip_unless_bind_unix_socket
async def test_unix_server_cleanup_prevented(self):
Expand Down