Skip to content

Commit

Permalink
Add workarounds for IPv6 bug in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uglide committed Oct 22, 2024
1 parent 412b293 commit cdb15ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
18 changes: 9 additions & 9 deletions tests/test_asyncio/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,22 @@ async def test_cluster_retry_object(self, request: FixtureRequest) -> None:
async with RedisCluster.from_url(url) as rc_default:
# Test default retry
retry = rc_default.connection_kwargs.get("retry")

# FIXME: Workaround for https://github.com/redis/redis-py/issues/3030
host = rc_default.get_default_node().host

assert isinstance(retry, Retry)
assert retry._retries == 3
assert isinstance(retry._backoff, type(default_backoff()))
assert rc_default.get_node("127.0.0.1", 16379).connection_kwargs.get(
assert rc_default.get_node(host, 16379).connection_kwargs.get(
"retry"
) == rc_default.get_node("127.0.0.1", 16380).connection_kwargs.get("retry")
) == rc_default.get_node(host, 16380).connection_kwargs.get("retry")

retry = Retry(ExponentialBackoff(10, 5), 5)
async with RedisCluster.from_url(url, retry=retry) as rc_custom_retry:
# Test custom retry
assert (
rc_custom_retry.get_node("127.0.0.1", 16379).connection_kwargs.get(
"retry"
)
rc_custom_retry.get_node(host, 16379).connection_kwargs.get("retry")
== retry
)

Expand All @@ -402,17 +404,15 @@ async def test_cluster_retry_object(self, request: FixtureRequest) -> None:
) as rc_no_retries:
# Test no connection retries
assert (
rc_no_retries.get_node("127.0.0.1", 16379).connection_kwargs.get(
"retry"
)
rc_no_retries.get_node(host, 16379).connection_kwargs.get("retry")
is None
)

async with RedisCluster.from_url(
url, retry=Retry(NoBackoff(), 0)
) as rc_no_retries:
assert (
rc_no_retries.get_node("127.0.0.1", 16379)
rc_no_retries.get_node(host, 16379)
.connection_kwargs.get("retry")
._retries
== 0
Expand Down
13 changes: 7 additions & 6 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,21 +862,22 @@ def test_cluster_get_set_retry_object(self, request):

def test_cluster_retry_object(self, r) -> None:
# Test default retry
# FIXME: Workaround for https://github.com/redis/redis-py/issues/3030
host = r.get_default_node().host

retry = r.get_connection_kwargs().get("retry")
assert isinstance(retry, Retry)
assert retry._retries == 0
assert isinstance(retry._backoff, type(default_backoff()))
node1 = r.get_node("127.0.0.1", 16379).redis_connection
node2 = r.get_node("127.0.0.1", 16380).redis_connection
node1 = r.get_node(host, 16379).redis_connection
node2 = r.get_node(host, 16380).redis_connection
assert node1.get_retry()._retries == node2.get_retry()._retries

# Test custom retry
retry = Retry(ExponentialBackoff(10, 5), 5)
rc_custom_retry = RedisCluster("127.0.0.1", 16379, retry=retry)
rc_custom_retry = RedisCluster(host, 16379, retry=retry)
assert (
rc_custom_retry.get_node("127.0.0.1", 16379)
.redis_connection.get_retry()
._retries
rc_custom_retry.get_node(host, 16379).redis_connection.get_retry()._retries
== retry._retries
)

Expand Down

0 comments on commit cdb15ce

Please sign in to comment.