Skip to content

Commit d9ad720

Browse files
committed
Fixed tests
1 parent bca7a31 commit d9ad720

File tree

4 files changed

+50
-56
lines changed

4 files changed

+50
-56
lines changed

redis/asyncio/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ async def _reinitialize_on_error(self, error):
22542254
await self._pipe.cluster_client.nodes_manager.initialize()
22552255
self.reinitialize_counter = 0
22562256
else:
2257-
if type(error) is MovedError:
2257+
if isinstance(error, AskError):
22582258
self._pipe.cluster_client.nodes_manager.update_moved_exception(
22592259
error
22602260
)

redis/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3165,7 +3165,7 @@ def _reinitialize_on_error(self, error):
31653165
self._nodes_manager.initialize()
31663166
self.reinitialize_counter = 0
31673167
else:
3168-
if type(error) is MovedError:
3168+
if isinstance(error, AskError):
31693169
self._nodes_manager.update_moved_exception(error)
31703170

31713171
self._executing = False

tests/test_asyncio/test_multidb/test_client.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -184,41 +184,38 @@ async def test_execute_command_against_correct_db_on_background_health_check_det
184184
indirect=True,
185185
)
186186
async def test_execute_command_auto_fallback_to_highest_weight_db(
187-
self, mock_multi_db_config, mock_db, mock_db1, mock_db2
187+
self, mock_multi_db_config, mock_db, mock_db1, mock_db2, mock_hc
188188
):
189189
databases = create_weighted_list(mock_db, mock_db1, mock_db2)
190+
mock_hc.check_health.side_effect = [
191+
True,
192+
True,
193+
True,
194+
False,
195+
True,
196+
True,
197+
True,
198+
True,
199+
True,
200+
True,
201+
True,
202+
True,
203+
True,
204+
True,
205+
True
206+
]
190207

191208
with (
192209
patch.object(mock_multi_db_config, "databases", return_value=databases),
193210
patch.object(
194211
mock_multi_db_config,
195212
"default_health_checks",
196-
return_value=[EchoHealthCheck()],
213+
return_value=[mock_hc],
197214
),
198215
):
199-
mock_db.client.execute_command.side_effect = [
200-
"healthcheck",
201-
"healthcheck",
202-
"healthcheck",
203-
"healthcheck",
204-
"healthcheck",
205-
]
206-
mock_db1.client.execute_command.side_effect = [
207-
"healthcheck",
208-
"OK1",
209-
"error",
210-
"healthcheck",
211-
"healthcheck",
212-
"OK1",
213-
]
214-
mock_db2.client.execute_command.side_effect = [
215-
"healthcheck",
216-
"healthcheck",
217-
"OK2",
218-
"healthcheck",
219-
"healthcheck",
220-
"healthcheck",
221-
]
216+
mock_db.client.execute_command.return_value = 'OK'
217+
mock_db1.client.execute_command.return_value = 'OK1'
218+
mock_db2.client.execute_command.return_value = 'OK2'
222219
mock_multi_db_config.health_check_interval = 0.1
223220
mock_multi_db_config.auto_fallback_interval = 0.2
224221
mock_multi_db_config.failover_strategy = WeightBasedFailoverStrategy()

tests/test_multidb/test_client.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,50 +180,47 @@ def test_execute_command_against_correct_db_on_background_health_check_determine
180180
indirect=True,
181181
)
182182
def test_execute_command_auto_fallback_to_highest_weight_db(
183-
self, mock_multi_db_config, mock_db, mock_db1, mock_db2
183+
self, mock_multi_db_config, mock_db, mock_db1, mock_db2, mock_hc
184184
):
185185
databases = create_weighted_list(mock_db, mock_db1, mock_db2)
186+
mock_hc.check_health.side_effect = [
187+
True,
188+
True,
189+
True,
190+
False,
191+
True,
192+
True,
193+
True,
194+
True,
195+
True,
196+
True,
197+
True,
198+
True,
199+
True,
200+
True,
201+
True
202+
]
186203

187204
with (
188205
patch.object(mock_multi_db_config, "databases", return_value=databases),
189206
patch.object(
190207
mock_multi_db_config,
191208
"default_health_checks",
192-
return_value=[EchoHealthCheck()],
209+
return_value=[mock_hc],
193210
),
194211
):
195-
mock_db.client.execute_command.side_effect = [
196-
"healthcheck",
197-
"healthcheck",
198-
"healthcheck",
199-
"healthcheck",
200-
"healthcheck",
201-
]
202-
mock_db1.client.execute_command.side_effect = [
203-
"healthcheck",
204-
"OK1",
205-
"error",
206-
"healthcheck",
207-
"healthcheck",
208-
"OK1",
209-
]
210-
mock_db2.client.execute_command.side_effect = [
211-
"healthcheck",
212-
"healthcheck",
213-
"OK2",
214-
"healthcheck",
215-
"healthcheck",
216-
"healthcheck",
217-
]
218-
mock_multi_db_config.health_check_interval = 0.2
219-
mock_multi_db_config.auto_fallback_interval = 0.4
212+
mock_db.client.execute_command.return_value = 'OK'
213+
mock_db1.client.execute_command.return_value = 'OK1'
214+
mock_db2.client.execute_command.return_value = 'OK2'
215+
mock_multi_db_config.health_check_interval = 0.1
216+
mock_multi_db_config.auto_fallback_interval = 0.2
220217
mock_multi_db_config.failover_strategy = WeightBasedFailoverStrategy()
221218

222219
client = MultiDBClient(mock_multi_db_config)
223220
assert client.set("key", "value") == "OK1"
224-
sleep(0.30)
221+
sleep(0.15)
225222
assert client.set("key", "value") == "OK2"
226-
sleep(0.44)
223+
sleep(0.22)
227224
assert client.set("key", "value") == "OK1"
228225

229226
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)