mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-11-23 16:06:32 +03:00
Socket occupation fix
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user