@@ -110,43 +110,37 @@ async def async_cluster_store(mock_async_redis_cluster):
110110 """Fixture to create an AsyncRedisStore with a mock Redis cluster client."""
111111 # Create a store with the mock Redis client
112112 # Pass the mock client explicitly as redis_client to avoid URL parsing
113- store = AsyncRedisStore (redis_client = mock_async_redis_cluster )
113+ async with AsyncRedisStore (redis_client = mock_async_redis_cluster ) as store :
114+ # Manually set cluster_mode to True for testing
115+ # This bypasses the automatic detection which is hard to mock in async context
116+ store .cluster_mode = True
114117
115- # Manually set cluster_mode to True for testing
116- # This bypasses the automatic detection which is hard to mock in async context
117- store .cluster_mode = True
118+ # Mock the store_index and vector_index
119+ mock_index = AsyncMock ()
120+ mock_docs = MagicMock ()
121+ mock_docs .docs = []
122+ mock_index .search .return_value = mock_docs
123+ mock_index .load .return_value = None
124+ mock_index .query .return_value = []
118125
119- # Mock the store_index and vector_index
120- mock_index = AsyncMock ()
121- mock_docs = MagicMock ()
122- mock_docs .docs = []
123- mock_index .search .return_value = mock_docs
124- mock_index .load .return_value = None
125- mock_index .query .return_value = []
126-
127- # Replace the real indices with mocks
128- store .store_index = mock_index
129- store .vector_index = mock_index
130-
131- yield store
132- await store .aclose ()
126+ # Replace the real indices with mocks
127+ store .store_index = mock_index
128+ store .vector_index = mock_index
129+ yield store
133130
134131
135132@pytest .mark .asyncio
136133async def test_async_cluster_mode_detection (mock_async_redis_cluster ):
137134 """Test that cluster mode can be manually set."""
138135 # Pass the mock client explicitly as redis_client to avoid URL parsing
139- store = AsyncRedisStore (redis_client = mock_async_redis_cluster )
140-
141- # Manually set cluster_mode for testing
142- store .cluster_mode = True
143- assert store .cluster_mode is True
144-
145- # Test with cluster_mode set to False
146- store .cluster_mode = False
147- assert store .cluster_mode is False
136+ async with AsyncRedisStore (redis_client = mock_async_redis_cluster ) as store :
137+ # Manually set cluster_mode for testing
138+ store .cluster_mode = True
139+ assert store .cluster_mode is True
148140
149- await store .aclose ()
141+ # Test with cluster_mode set to False
142+ store .cluster_mode = False
143+ assert store .cluster_mode is False
150144
151145
152146@pytest .mark .asyncio
@@ -161,7 +155,7 @@ async def test_async_hash_tag_in_keys(async_cluster_store, mock_async_redis_clus
161155 assert key == f"{ STORE_PREFIX } { REDIS_KEY_SEPARATOR } test_id"
162156
163157 # Put a value in the store to generate keys
164- await async_cluster_store .put (("test" ,), "key1" , {"data" : "value1" })
158+ await async_cluster_store .aput (("test" ,), "key1" , {"data" : "value1" })
165159
166160 # Check that keys in delete calls have hash tags
167161 # Note: This is an indirect test as we're checking the mock's recorded calls
@@ -183,7 +177,7 @@ async def test_async_pipeline_transaction_false(async_cluster_store, mock_async_
183177 assert call ["transaction" ] is False , "Pipeline should be created with transaction=False in cluster mode"
184178
185179 # Put a value to trigger more pipeline usage
186- await async_cluster_store .put (("test" ,), "key1" , {"data" : "value1" })
180+ await async_cluster_store .aput (("test" ,), "key1" , {"data" : "value1" })
187181
188182 # Check again
189183 assert len (mock_async_redis_cluster .pipeline_calls ) > 0
0 commit comments