| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import asyncio | ||
| import os | ||
| import socket | ||
| import time | ||
| import threading | ||
| import unittest | ||
| Expand Down Expand Up | @@ -147,6 +149,80 @@ async def serve(*args): | |
| await task2 | ||
|
|
||
|
|
||
| # Test the various corner cases of Unix server socket removal | ||
| class UnixServerCleanupTests(unittest.IsolatedAsyncioTestCase): | ||
| @socket_helper.skip_unless_bind_unix_socket | ||
| async def test_unix_server_addr_cleanup(self): | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWould you mind adding one-line comments to the new tests explaining what each test checks? They look so similar I first thought you had accidentally copied the test a few times. :-)
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySure. A commit with comments have been pushed.
Sorry, something went wrong.
All reactions
|
||
| # Default scenario | ||
| with test_utils.unix_socket_path() as addr: | ||
| async def serve(*args): | ||
| pass | ||
|
|
||
| srv = await asyncio.start_unix_server(serve, addr) | ||
|
|
||
| srv.close() | ||
| self.assertFalse(os.path.exists(addr)) | ||
|
|
||
| @socket_helper.skip_unless_bind_unix_socket | ||
| async def test_unix_server_sock_cleanup(self): | ||
| # Using already bound socket | ||
| with test_utils.unix_socket_path() as addr: | ||
| async def serve(*args): | ||
| pass | ||
|
|
||
| sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| sock.bind(addr) | ||
|
|
||
| srv = await asyncio.start_unix_server(serve, sock=sock) | ||
|
|
||
| srv.close() | ||
| self.assertFalse(os.path.exists(addr)) | ||
|
|
||
| @socket_helper.skip_unless_bind_unix_socket | ||
| async def test_unix_server_cleanup_gone(self): | ||
| # Someone else has already cleaned up the socket | ||
| with test_utils.unix_socket_path() as addr: | ||
| async def serve(*args): | ||
| pass | ||
|
|
||
| sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| sock.bind(addr) | ||
|
|
||
| srv = await asyncio.start_unix_server(serve, sock=sock) | ||
|
|
||
| os.unlink(addr) | ||
|
|
||
| srv.close() | ||
|
|
||
| @socket_helper.skip_unless_bind_unix_socket | ||
| async def test_unix_server_cleanup_replaced(self): | ||
| # Someone else has replaced the socket with their own | ||
| with test_utils.unix_socket_path() as addr: | ||
| async def serve(*args): | ||
| pass | ||
|
|
||
| srv = await asyncio.start_unix_server(serve, addr) | ||
|
|
||
| os.unlink(addr) | ||
| sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| sock.bind(addr) | ||
|
|
||
| srv.close() | ||
| self.assertTrue(os.path.exists(addr)) | ||
|
|
||
| @socket_helper.skip_unless_bind_unix_socket | ||
| async def test_unix_server_cleanup_prevented(self): | ||
| # Automatic cleanup explicitly disabled | ||
| with test_utils.unix_socket_path() as addr: | ||
| async def serve(*args): | ||
| pass | ||
|
|
||
| srv = await asyncio.start_unix_server(serve, addr, cleanup_socket=False) | ||
|
|
||
| srv.close() | ||
| self.assertTrue(os.path.exists(addr)) | ||
|
|
||
|
|
||
| @unittest.skipUnless(hasattr(asyncio, 'ProactorEventLoop'), 'Windows only') | ||
| class ProactorStartServerTests(BaseStartServer, unittest.TestCase): | ||
|
|
||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| :meth:`asyncio.loop.create_unix_server` will now automatically remove the | ||
| Unix socket when the server is closed. |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.