Socket occupation fix

This commit is contained in:
Flowseal
2026-11-23 06:28:14 +03:00
parent 0970820f1f
commit 13d764f809
9 changed files with 295 additions and 41 deletions
+29
View File
@@ -26,6 +26,35 @@ def _wake_later(loop, callback):
return thread
class ClientSetupTest(unittest.IsolatedAsyncioTestCase):
async def test_fin_cancels_pending_setup_and_closes_accepted_socket(self):
started, cancelled = asyncio.Event(), asyncio.Event()
async def handle(reader, writer):
try:
with event_loop.client_setup(reader, writer):
started.set()
await asyncio.Future()
except asyncio.CancelledError:
cancelled.set()
finally:
writer.close()
await writer.wait_closed()
loop = asyncio.get_running_loop()
server = await loop.create_server(lambda: event_loop.ClientStreamProtocol(handle), '127.0.0.1', 0)
async with server:
peer, writer = await asyncio.open_connection('127.0.0.1', server.sockets[0].getsockname()[1])
try:
await asyncio.wait_for(started.wait(), 1)
writer.write_eof()
await asyncio.wait_for(cancelled.wait(), 1)
self.assertEqual(await asyncio.wait_for(peer.read(1), 1), b'')
finally:
writer.close()
await writer.wait_closed()
@unittest.skipUnless(sys.platform == 'win32', 'Windows proactor self-pipe')
class WindowsSelfPipeTest(unittest.TestCase):
def setUp(self):