From 3748a8b36d5c765f5d21c6d20b041fa1876021ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 7 May 2023 19:33:14 +0000 Subject: 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 --- tests/test_cluster.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'tests/test_cluster.py') 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() -- cgit v1.2.1