@@ -29,15 +29,6 @@ def __init__(self, *args, **kwargs):
2929 self .delete_calls = []
3030 self .json_get_calls = []
3131
32- def cluster (self , command , * args , ** kwargs ):
33- """Mock synchronous cluster command that returns cluster info.
34-
35- This is called by BaseRedisStore.__init__ to detect cluster mode.
36- """
37- if command == "info" :
38- return {"cluster_state" : "ok" }
39- raise ResponseError (f"Unknown cluster command: { command } " )
40-
4132 async def cluster (self , command , * args , ** kwargs ): # type: ignore
4233 """Mock asynchronous cluster command that returns cluster info.
4334
@@ -125,9 +116,12 @@ async def async_cluster_store(mock_async_redis_cluster):
125116 # Create a store with the mock Redis client
126117 # Pass the mock client explicitly as redis_client to avoid URL parsing
127118 async with AsyncRedisStore (redis_client = mock_async_redis_cluster ) as store :
128- # Manually set cluster_mode to True for testing
129- # This bypasses the automatic detection which is hard to mock in async context
130- store .cluster_mode = True
119+ # The cluster_mode will be automatically detected during setup
120+ # Call setup to ensure cluster mode is detected
121+ await store .detect_cluster_mode ()
122+
123+ # Verify that cluster mode was detected
124+ assert store .cluster_mode is True
131125
132126 # Mock the store_index and vector_index
133127 mock_index = AsyncMock ()
@@ -145,16 +139,32 @@ async def async_cluster_store(mock_async_redis_cluster):
145139
146140@pytest .mark .asyncio
147141async def test_async_cluster_mode_detection (mock_async_redis_cluster ):
148- """Test that cluster mode can be manually set ."""
142+ """Test that cluster mode is automatically detected ."""
149143 # Pass the mock client explicitly as redis_client to avoid URL parsing
150144 async with AsyncRedisStore (redis_client = mock_async_redis_cluster ) as store :
151- # Manually set cluster_mode for testing
152- store .cluster_mode = True
145+ # Cluster mode should be initialized to False
146+ assert store .cluster_mode is False
147+
148+ # Call detect_cluster_mode to detect cluster mode
149+ await store .detect_cluster_mode ()
150+
151+ # Cluster mode should be detected as True
153152 assert store .cluster_mode is True
154153
155- # Test with cluster_mode set to False
156- store .cluster_mode = False
157- assert store .cluster_mode is False
154+ # Test with a non-cluster Redis client by patching the cluster method
155+ with patch .object (
156+ mock_async_redis_cluster ,
157+ "cluster" ,
158+ side_effect = ResponseError ("cluster command not allowed" ),
159+ ):
160+ # Reset cluster_mode to False
161+ store .cluster_mode = False
162+
163+ # Call detect_cluster_mode again
164+ await store .detect_cluster_mode ()
165+
166+ # Cluster mode should remain False
167+ assert store .cluster_mode is False
158168
159169
160170@pytest .mark .asyncio
0 commit comments