|
13 | 13 | import pytest |
14 | 14 |
|
15 | 15 | from redis import Redis |
16 | | -from redis.backoff import ExponentialBackoff, NoBackoff, default_backoff, ConstantBackoff |
| 16 | +from redis.backoff import ( |
| 17 | + ConstantBackoff, |
| 18 | + ExponentialBackoff, |
| 19 | + NoBackoff, |
| 20 | + default_backoff, |
| 21 | +) |
17 | 22 | from redis.cluster import ( |
18 | 23 | PRIMARY, |
19 | 24 | REDIS_CLUSTER_HASH_SLOTS, |
|
36 | 41 | RedisClusterException, |
37 | 42 | RedisError, |
38 | 43 | ResponseError, |
39 | | - TimeoutError, SlotNotCoveredError, |
| 44 | + SlotNotCoveredError, |
| 45 | + TimeoutError, |
40 | 46 | ) |
41 | 47 | from redis.retry import Retry |
42 | 48 | from redis.utils import str_if_bytes |
@@ -901,29 +907,33 @@ def address_remap(address): |
901 | 907 | n_used = sum((1 if p.n_connections else 0) for p in proxies) |
902 | 908 | assert n_used > 1 |
903 | 909 |
|
904 | | - @pytest.mark.parametrize('error', [ConnectionError, TimeoutError]) |
| 910 | + @pytest.mark.parametrize("error", [ConnectionError, TimeoutError]) |
905 | 911 | def test_additional_backoff_redis_cluster(self, error): |
906 | 912 | with patch.object(ConstantBackoff, "compute") as compute: |
| 913 | + |
907 | 914 | def _compute(target_node, *args, **kwargs): |
908 | 915 | return 1 |
909 | 916 |
|
910 | 917 | compute.side_effect = _compute |
911 | 918 | with patch.object(RedisCluster, "_execute_command") as execute_command: |
| 919 | + |
912 | 920 | def raise_error(target_node, *args, **kwargs): |
913 | 921 | execute_command.failed_calls += 1 |
914 | 922 | raise error("mocked error") |
915 | 923 |
|
916 | 924 | execute_command.side_effect = raise_error |
917 | 925 |
|
918 | 926 | rc = get_mocked_redis_client( |
919 | | - host=default_host, port=default_port, retry=Retry(ConstantBackoff(1), 3) |
| 927 | + host=default_host, |
| 928 | + port=default_port, |
| 929 | + retry=Retry(ConstantBackoff(1), 3), |
920 | 930 | ) |
921 | 931 |
|
922 | 932 | with pytest.raises(error): |
923 | 933 | rc.get("bar") |
924 | 934 | assert compute.call_count == rc.cluster_error_retry_attempts |
925 | 935 |
|
926 | | - @pytest.mark.parametrize('reinitialize_steps', [2, 10, 99]) |
| 936 | + @pytest.mark.parametrize("reinitialize_steps", [2, 10, 99]) |
927 | 937 | def test_recover_slot_not_covered_error(self, request, reinitialize_steps): |
928 | 938 | rc = _get_client(RedisCluster, request, reinitialize_steps=reinitialize_steps) |
929 | 939 | key = uuid.uuid4().hex |
|
0 commit comments