From 7f6c0adf924ac6b40a652f1a0f0eaa50749c6eba Mon Sep 17 00:00:00 2001 From: dvora-h Date: Wed, 29 Mar 2023 14:03:59 +0300 Subject: [PATCH] Fix async --- redis/asyncio/client.py | 10 ++----- tests/test_asyncio/test_cwe_404.py | 45 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 7986b11cbd..3e6626aedf 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -1227,13 +1227,9 @@ async def immediate_execute_command(self, *args, **options): command_name, self.shard_hint ) self.connection = conn - try: - return await asyncio.shield( - self._try_send_command_parse_response(conn, *args, **options) - ) - except asyncio.CancelledError: - await conn.disconnect() - raise + return await asyncio.shield( + self._try_send_command_parse_response(conn, *args, **options) + ) def pipeline_execute_command(self, *args, **options): """ diff --git a/tests/test_asyncio/test_cwe_404.py b/tests/test_asyncio/test_cwe_404.py index 668344042d..dc62df65f4 100644 --- a/tests/test_asyncio/test_cwe_404.py +++ b/tests/test_asyncio/test_cwe_404.py @@ -88,34 +88,35 @@ async def test_standalone_pipeline(delay): addr=("localhost", 5380), redis_addr=("localhost", 6379), delay=delay * 2 ) await dp.start() - async with Redis(host="localhost", port=5380) as r: - await r.set("foo", "foo") - await r.set("bar", "bar") + for b in [True, False]: + async with Redis(host="localhost", port=5380, single_connection_client=b) as r: + await r.set("foo", "foo") + await r.set("bar", "bar") - pipe = r.pipeline() + pipe = r.pipeline() - pipe2 = r.pipeline() - pipe2.get("bar") - pipe2.ping() - pipe2.get("foo") + pipe2 = r.pipeline() + pipe2.get("bar") + pipe2.ping() + pipe2.get("foo") - t = asyncio.create_task(pipe.get("foo").execute()) - await asyncio.sleep(delay) - t.cancel() + t = asyncio.create_task(pipe.get("foo").execute()) + await asyncio.sleep(delay) + t.cancel() - pipe.get("bar") - pipe.ping() - pipe.get("foo") - pipe.reset() + pipe.get("bar") + pipe.ping() + pipe.get("foo") + pipe.reset() - assert await pipe.execute() is None + assert await pipe.execute() is None - # validating that the pipeline can be used as it could previously - pipe.get("bar") - pipe.ping() - pipe.get("foo") - assert await pipe.execute() == [b"bar", True, b"foo"] - assert await pipe2.execute() == [b"bar", True, b"foo"] + # validating that the pipeline can be used as it could previously + pipe.get("bar") + pipe.ping() + pipe.get("foo") + assert await pipe.execute() == [b"bar", True, b"foo"] + assert await pipe2.execute() == [b"bar", True, b"foo"] await dp.stop()