diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index 82f55c55..96c3d9f1 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -60,6 +60,7 @@ def __init__(self, addr, valkey_addr): self.send_event = asyncio.Event() self.server = None self.task = None + self.pipes = None self.n_connections = 0 async def start(self): @@ -79,12 +80,18 @@ async def handle(self, reader, writer): self.n_connections += 1 pipe1 = asyncio.create_task(self.pipe(reader, valkey_writer)) pipe2 = asyncio.create_task(self.pipe(valkey_reader, writer)) - await asyncio.gather(pipe1, pipe2) + self.pipes = asyncio.gather(pipe1, pipe2) + await self.pipes + except asyncio.CancelledError: + writer.close() finally: valkey_writer.close() async def aclose(self): self.task.cancel() + # self.pipes can be None if handle was never called + if self.pipes is not None: + self.pipes.cancel() try: await self.task except asyncio.CancelledError: