|
12 | 12 | import pytest
|
13 | 13 |
|
14 | 14 | from redis import Redis
|
15 |
| -from redis.backoff import ExponentialBackoff, NoBackoff, default_backoff |
| 15 | +from redis.backoff import ExponentialBackoff, NoBackoff, default_backoff, ConstantBackoff |
16 | 16 | from redis.cluster import (
|
17 | 17 | PRIMARY,
|
18 | 18 | REDIS_CLUSTER_HASH_SLOTS,
|
@@ -900,6 +900,28 @@ def address_remap(address):
|
900 | 900 | n_used = sum((1 if p.n_connections else 0) for p in proxies)
|
901 | 901 | assert n_used > 1
|
902 | 902 |
|
| 903 | + @pytest.mark.parametrize('error', [ConnectionError, TimeoutError]) |
| 904 | + def test_additional_backoff_redis_cluster(self, error): |
| 905 | + with patch.object(ConstantBackoff, "compute") as compute: |
| 906 | + def _compute(target_node, *args, **kwargs): |
| 907 | + return 1 |
| 908 | + |
| 909 | + compute.side_effect = _compute |
| 910 | + with patch.object(RedisCluster, "_execute_command") as execute_command: |
| 911 | + def raise_error(target_node, *args, **kwargs): |
| 912 | + execute_command.failed_calls += 1 |
| 913 | + raise error("mocked error") |
| 914 | + |
| 915 | + execute_command.side_effect = raise_error |
| 916 | + |
| 917 | + rc = get_mocked_redis_client( |
| 918 | + host=default_host, port=default_port, retry=Retry(ConstantBackoff(1), 3) |
| 919 | + ) |
| 920 | + |
| 921 | + with pytest.raises(error): |
| 922 | + rc.get("bar") |
| 923 | + assert compute.call_count == rc.cluster_error_retry_attempts |
| 924 | + |
903 | 925 |
|
904 | 926 | @pytest.mark.onlycluster
|
905 | 927 | class TestClusterRedisCommands:
|
|
0 commit comments