diff options
author | Utkarsh Gupta <utkarshgupta137@gmail.com> | 2022-06-19 07:16:02 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-19 04:46:02 +0300 |
commit | 33702983b8b0a55d29189babb631ea108ee8404f (patch) | |
tree | 3ddc0aeb574b0cf1f7c665b32d74a92c1377ba5b | |
parent | 2ee61f0b5c54df54ebfc382eea2661d709ce9c73 (diff) | |
download | redis-py-33702983b8b0a55d29189babb631ea108ee8404f.tar.gz |
async_cluster: fix simultaneous initialize (#2231)
- close startup_nodes too during client.close(), in case they are different
-rw-r--r-- | redis/asyncio/cluster.py | 4 | ||||
-rw-r--r-- | tests/test_asyncio/test_cluster.py | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/redis/asyncio/cluster.py b/redis/asyncio/cluster.py index 89789b7..a7bea30 100644 --- a/redis/asyncio/cluster.py +++ b/redis/asyncio/cluster.py @@ -323,14 +323,13 @@ class RedisCluster(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommand if self._initialize: async with self._lock: if self._initialize: - self._initialize = False try: await self.nodes_manager.initialize() await self.commands_parser.initialize( self.nodes_manager.default_node ) + self._initialize = False except BaseException: - self._initialize = True await self.nodes_manager.close() await self.nodes_manager.close("startup_nodes") raise @@ -343,6 +342,7 @@ class RedisCluster(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommand if not self._initialize: self._initialize = True await self.nodes_manager.close() + await self.nodes_manager.close("startup_nodes") async def __aenter__(self) -> "RedisCluster": return await self.initialize() diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index 0c676cb..e5ec026 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -680,13 +680,15 @@ class TestRedisClusterObj: else: raise e - async def test_can_run_concurrent_commands(self, r: RedisCluster) -> None: - assert await r.ping(target_nodes=RedisCluster.ALL_NODES) is True + async def test_can_run_concurrent_commands(self, request: FixtureRequest) -> None: + url = request.config.getoption("--redis-url") + rc = RedisCluster.from_url(url) assert all( await asyncio.gather( - *(r.ping(target_nodes=RedisCluster.ALL_NODES) for _ in range(100)) + *(rc.echo("i", target_nodes=RedisCluster.ALL_NODES) for i in range(100)) ) ) + await rc.close() @pytest.mark.onlycluster |