summaryrefslogtreecommitdiff
path: root/tests/test_cluster.py
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2023-05-07 19:33:14 +0000
committerGitHub <noreply@github.com>2023-05-07 22:33:14 +0300
commit3748a8b36d5c765f5d21c6d20b041fa1876021ae (patch)
tree1e9602c147fdd922374761f79eca1e9a35a32fae /tests/test_cluster.py
parentffb2b83468123c314d2742d1b1e68e6ce9eeb244 (diff)
downloadredis-py-3748a8b36d5c765f5d21c6d20b041fa1876021ae.tar.gz
Add RedisCluster.remap_host_port, Update tests for CWE 404 (#2706)
* Use provided redis address. Bind to IPv4 * Add missing "await" and perform the correct test for pipe eimpty * Wait for a send event, rather than rely on sleep time. Excpect cancel errors. * set delay to 0 except for operation we want to cancel This speeds up the unit tests considerably by eliminating unnecessary delay. * Release resources in test * Fix cluster test to use address_remap and multiple proxies. * Use context manager to manage DelayProxy * Mark failing pipeline tests * lint * Use a common "master_host" test fixture
Diffstat (limited to 'tests/test_cluster.py')
-rw-r--r--tests/test_cluster.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/tests/test_cluster.py b/tests/test_cluster.py
index 1f037c9..8371cc5 100644
--- a/tests/test_cluster.py
+++ b/tests/test_cluster.py
@@ -8,7 +8,6 @@ import warnings
from queue import LifoQueue, Queue
from time import sleep
from unittest.mock import DEFAULT, Mock, call, patch
-from urllib.parse import urlparse
import pytest
@@ -125,18 +124,6 @@ class NodeProxy:
self.server.shutdown()
-@pytest.fixture
-def redis_addr(request):
- redis_url = request.config.getoption("--redis-url")
- scheme, netloc = urlparse(redis_url)[:2]
- assert scheme == "redis"
- if ":" in netloc:
- host, port = netloc.split(":")
- return host, int(port)
- else:
- return netloc, 6379
-
-
@pytest.fixture()
def slowlog(request, r):
"""
@@ -907,7 +894,7 @@ class TestRedisClusterObj:
assert "myself" not in nodes.get(curr_default_node.name).get("flags")
assert r.get_default_node() != curr_default_node
- def test_address_remap(self, request, redis_addr):
+ def test_address_remap(self, request, master_host):
"""Test that we can create a rediscluster object with
a host-port remapper and map connections through proxy objects
"""
@@ -915,7 +902,8 @@ class TestRedisClusterObj:
# we remap the first n nodes
offset = 1000
n = 6
- ports = [redis_addr[1] + i for i in range(n)]
+ hostname, master_port = master_host
+ ports = [master_port + i for i in range(n)]
def address_remap(address):
# remap first three nodes to our local proxy
@@ -928,8 +916,7 @@ class TestRedisClusterObj:
# create the proxies
proxies = [
- NodeProxy(("127.0.0.1", port + offset), (redis_addr[0], port))
- for port in ports
+ NodeProxy(("127.0.0.1", port + offset), (hostname, port)) for port in ports
]
for p in proxies:
p.start()