Skip to content

Commit a382fda

Browse files
committed
[GROW-2938] add a test for pipeline additional backoff
1 parent 2ff62e6 commit a382fda

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/test_cluster.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def raise_error(target_node, *args, **kwargs):
929929
rc = get_mocked_redis_client(
930930
host=default_host,
931931
port=default_port,
932-
retry=Retry(ConstantBackoff(1), 3),
932+
retry=Retry(ConstantBackoff(1), 10),
933933
)
934934

935935
with pytest.raises(error):
@@ -3091,6 +3091,33 @@ def test_empty_stack(self, r):
30913091
result = p.execute()
30923092
assert result == []
30933093

3094+
@pytest.mark.parametrize("error", [ConnectionError, TimeoutError])
3095+
def test_additional_backoff_cluster_pipeline(self, r, error):
3096+
with patch.object(ConstantBackoff, "compute") as compute:
3097+
3098+
def _compute(target_node, *args, **kwargs):
3099+
return 1
3100+
3101+
compute.side_effect = _compute
3102+
with patch("redis.cluster.get_connection") as get_connection:
3103+
3104+
def raise_error(target_node, *args, **kwargs):
3105+
get_connection.failed_calls += 1
3106+
raise error("mocked error")
3107+
3108+
get_connection.side_effect = raise_error
3109+
3110+
r.set_retry(Retry(ConstantBackoff(1), 10))
3111+
pipeline = r.pipeline()
3112+
3113+
with pytest.raises(error):
3114+
pipeline.get("bar")
3115+
pipeline.get("bar")
3116+
pipeline.execute()
3117+
# cluster pipeline does one more back off than a single Redis command
3118+
# this is not required, but it's just how it's implemented as of now
3119+
assert compute.call_count == r.cluster_error_retry_attempts + 1
3120+
30943121

30953122
@pytest.mark.onlycluster
30963123
class TestReadOnlyPipeline:

0 commit comments

Comments
 (0)