|
33 | 33 | from redis.crc import key_slot |
34 | 34 | from redis.exceptions import ( |
35 | 35 | AskError, |
| 36 | + AuthenticationError, |
36 | 37 | ClusterDownError, |
37 | 38 | ConnectionError, |
38 | 39 | DataError, |
| 40 | + MaxConnectionsError, |
39 | 41 | MovedError, |
40 | 42 | NoPermissionError, |
41 | 43 | RedisClusterException, |
@@ -821,6 +823,21 @@ def raise_error(target_node, *args, **kwargs): |
821 | 823 | rc.get("bar") |
822 | 824 | assert compute.call_count == rc.cluster_error_retry_attempts |
823 | 825 |
|
| 826 | + @pytest.mark.parametrize("error", [AuthenticationError, MaxConnectionsError]) |
| 827 | + def test_skip_initialize(self, r, error): |
| 828 | + for n in r.nodes_manager.nodes_cache.values(): |
| 829 | + n.redis_connection.connection_pool.max_connections = 3 |
| 830 | + for _ in range(0, n.redis_connection.connection_pool.max_connections): |
| 831 | + n.redis_connection.connection_pool.get_connection("GET") |
| 832 | + |
| 833 | + with patch.object(NodesManager, "initialize") as i: |
| 834 | + with pytest.raises(MaxConnectionsError): |
| 835 | + r.get("a") |
| 836 | + assert i.call_count == 0 |
| 837 | + |
| 838 | + for n in r.nodes_manager.nodes_cache.values(): |
| 839 | + n.redis_connection.connection_pool.reset() |
| 840 | + |
824 | 841 | @pytest.mark.parametrize("reinitialize_steps", [2, 10, 99]) |
825 | 842 | def test_recover_slot_not_covered_error(self, request, reinitialize_steps): |
826 | 843 | rc = _get_client(RedisCluster, request, reinitialize_steps=reinitialize_steps) |
@@ -3079,7 +3096,49 @@ def test_empty_stack(self, r): |
3079 | 3096 | result = p.execute() |
3080 | 3097 | assert result == [] |
3081 | 3098 |
|
| 3099 | + @pytest.mark.parametrize("error", [AuthenticationError, MaxConnectionsError]) |
| 3100 | + def test_error_does_not_trigger_initialize(self, r, error): |
| 3101 | + with patch("redis.cluster.get_connection") as get_connection: |
| 3102 | + |
| 3103 | + def raise_error(target_node, *args, **kwargs): |
| 3104 | + get_connection.failed_calls += 1 |
| 3105 | + raise error("mocked error") |
| 3106 | + |
| 3107 | + get_connection.side_effect = raise_error |
| 3108 | + |
| 3109 | + r.set_retry(Retry(ConstantBackoff(0.1), 5)) |
| 3110 | + pipeline = r.pipeline() |
| 3111 | + |
| 3112 | + with patch.object(NodesManager, "initialize") as i: |
| 3113 | + with pytest.raises(error): |
| 3114 | + pipeline.get("bar") |
| 3115 | + pipeline.get("bar") |
| 3116 | + pipeline.execute() |
| 3117 | + assert i.call_count == 0 |
| 3118 | + |
3082 | 3119 | @pytest.mark.parametrize("error", [ConnectionError, TimeoutError]) |
| 3120 | + def test_error_trigger_initialize(self, r, error): |
| 3121 | + with patch("redis.cluster.get_connection") as get_connection: |
| 3122 | + |
| 3123 | + def raise_error(target_node, *args, **kwargs): |
| 3124 | + get_connection.failed_calls += 1 |
| 3125 | + raise error("mocked error") |
| 3126 | + |
| 3127 | + get_connection.side_effect = raise_error |
| 3128 | + |
| 3129 | + r.set_retry(Retry(ConstantBackoff(0.1), 5)) |
| 3130 | + pipeline = r.pipeline() |
| 3131 | + |
| 3132 | + with patch.object(NodesManager, "initialize") as i: |
| 3133 | + with pytest.raises(error): |
| 3134 | + pipeline.get("bar") |
| 3135 | + pipeline.get("bar") |
| 3136 | + pipeline.execute() |
| 3137 | + assert i.call_count == r.cluster_error_retry_attempts + 1 |
| 3138 | + |
| 3139 | + @pytest.mark.parametrize( |
| 3140 | + "error", [ConnectionError, TimeoutError, MaxConnectionsError] |
| 3141 | + ) |
3083 | 3142 | def test_additional_backoff_cluster_pipeline(self, r, error): |
3084 | 3143 | with patch.object(ConstantBackoff, "compute") as compute: |
3085 | 3144 |
|
|
0 commit comments