summaryrefslogtreecommitdiff
path: root/tests/test_asyncio/test_retry.py
diff options
context:
space:
mode:
authorBar Shaul <88437685+barshaul@users.noreply.github.com>2022-11-10 13:16:49 +0200
committerGitHub <noreply@github.com>2022-11-10 13:16:49 +0200
commit67214cc3eaa7890c87e45550b8320779f954094b (patch)
tree3bca8b8913224255bdf72de79265ca0441cecb1c /tests/test_asyncio/test_retry.py
parentbb06ccd52924800ac501d17c8a42038c8e5c5770 (diff)
downloadredis-py-67214cc3eaa7890c87e45550b8320779f954094b.tar.gz
Failover handling improvements for RedisCluster and Async RedisCluster (#2377)
* Cluster&AsyncCluster: Removed handling of timeouts/connection errors within the cluster loop, fixed "cannot pickle '_thread.lock' object" bug, added client's side failover handling improvements * Fixed linters * Type fixes * Added to CHANGES * Added getter and setter for the client's retry object and added more tests * Fixed linters * Fixed test * Fixed test_client_kill test * Changed get_default_backoff to default_backoff, removed retry_on_error and connection_error_retry_attempts from RedisCluster, default retry changed to no retries * Fixing linters * Reverting deletion of connection_error_retry_attempts to maintain backward compatibility * Updating retry object for existing and new connections * Changed the default value of reinitialize_steps from 10 to 5 * fix review comments Co-authored-by: Chayim <chayim@users.noreply.github.com> Co-authored-by: dvora-h <dvora.heller@redis.com> Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Diffstat (limited to 'tests/test_asyncio/test_retry.py')
-rw-r--r--tests/test_asyncio/test_retry.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_asyncio/test_retry.py b/tests/test_asyncio/test_retry.py
index 38e353b..86e6ddf 100644
--- a/tests/test_asyncio/test_retry.py
+++ b/tests/test_asyncio/test_retry.py
@@ -1,8 +1,9 @@
import pytest
+from redis.asyncio import Redis
from redis.asyncio.connection import Connection, UnixDomainSocketConnection
from redis.asyncio.retry import Retry
-from redis.backoff import AbstractBackoff, NoBackoff
+from redis.backoff import AbstractBackoff, ExponentialBackoff, NoBackoff
from redis.exceptions import ConnectionError, TimeoutError
@@ -114,3 +115,22 @@ class TestRetry:
assert self.actual_attempts == 5
assert self.actual_failures == 5
+
+
+class TestRedisClientRetry:
+ "Test the Redis client behavior with retries"
+
+ async def test_get_set_retry_object(self, request):
+ retry = Retry(NoBackoff(), 2)
+ url = request.config.getoption("--redis-url")
+ r = await Redis.from_url(url, retry_on_timeout=True, retry=retry)
+ assert r.get_retry()._retries == retry._retries
+ assert isinstance(r.get_retry()._backoff, NoBackoff)
+ new_retry_policy = Retry(ExponentialBackoff(), 3)
+ exiting_conn = await r.connection_pool.get_connection("_")
+ r.set_retry(new_retry_policy)
+ assert r.get_retry()._retries == new_retry_policy._retries
+ assert isinstance(r.get_retry()._backoff, ExponentialBackoff)
+ assert exiting_conn.retry._retries == new_retry_policy._retries
+ new_conn = await r.connection_pool.get_connection("_")
+ assert new_conn.retry._retries == new_retry_policy._retries