summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim I. Kirshen <c@kirshen.com>2021-11-10 14:17:27 +0200
committerChayim I. Kirshen <c@kirshen.com>2021-11-10 14:17:27 +0200
commitb8fbc6fe9f836e6c262b64581037851b91b77bf8 (patch)
tree9ed1b21e1b98589b979afb451f922af4ab6f7a5e
parent939fead8d375cdc90c205ebd81b26d986d6d0dc3 (diff)
downloadredis-py-b8fbc6fe9f836e6c262b64581037851b91b77bf8.tar.gz
Fixing multiprocessing tests to respect redisurl ports
-rw-r--r--tests/conftest.py20
-rw-r--r--tests/test_connection_pool.py17
-rw-r--r--tests/test_multiprocessing.py11
-rw-r--r--tests/test_sentinel.py2
4 files changed, 30 insertions, 20 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index b1a0f8c..3ba52a5 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -11,7 +11,6 @@ from urllib.parse import urlparse
REDIS_INFO = {}
default_redis_url = "redis://localhost:6379/9"
-default_redismod_url = "redis://localhost:36379/9"
default_redismod_url = "redis://localhost:36379"
@@ -44,10 +43,13 @@ def pytest_sessionstart(session):
REDIS_INFO["version"] = version
REDIS_INFO["arch_bits"] = arch_bits
- # module info
- redismod_url = session.config.getoption("--redismod-url")
- info = _get_info(redismod_url)
- REDIS_INFO["modules"] = info["modules"]
+ # module info, if the second redis is running
+ try:
+ redismod_url = session.config.getoption("--redismod-url")
+ info = _get_info(redismod_url)
+ REDIS_INFO["modules"] = info["modules"]
+ except redis.exceptions.ConnectionError:
+ pass
def skip_if_server_version_lt(min_version):
@@ -72,7 +74,11 @@ def skip_unless_arch_bits(arch_bits):
def skip_ifmodversion_lt(min_version: str, module_name: str):
- modules = REDIS_INFO["modules"]
+ try:
+ modules = REDIS_INFO["modules"]
+ except KeyError:
+ return pytest.mark.skipif(True,
+ reason="No redismod-url server running")
if modules == []:
return pytest.mark.skipif(True, reason="No redis modules found")
@@ -218,7 +224,7 @@ def mock_cluster_resp_slaves(request, **kwargs):
def master_host(request):
url = request.config.getoption("--redis-url")
parts = urlparse(url)
- yield parts.hostname
+ yield parts.hostname, parts.port
def wait_for_command(client, monitor, command):
diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py
index 8d2ad04..6fedec6 100644
--- a/tests/test_connection_pool.py
+++ b/tests/test_connection_pool.py
@@ -44,14 +44,14 @@ class TestConnectionPool:
assert connection.kwargs == connection_kwargs
def test_multiple_connections(self, master_host):
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(connection_kwargs=connection_kwargs)
c1 = pool.get_connection('_')
c2 = pool.get_connection('_')
assert c1 != c2
def test_max_connections(self, master_host):
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(max_connections=2,
connection_kwargs=connection_kwargs)
pool.get_connection('_')
@@ -60,7 +60,7 @@ class TestConnectionPool:
pool.get_connection('_')
def test_reuse_previously_released_connection(self, master_host):
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(connection_kwargs=connection_kwargs)
c1 = pool.get_connection('_')
pool.release(c1)
@@ -103,14 +103,15 @@ class TestBlockingConnectionPool:
return pool
def test_connection_creation(self, master_host):
- connection_kwargs = {'foo': 'bar', 'biz': 'baz', 'host': master_host}
+ connection_kwargs = {'foo': 'bar', 'biz': 'baz',
+ 'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(connection_kwargs=connection_kwargs)
connection = pool.get_connection('_')
assert isinstance(connection, DummyConnection)
assert connection.kwargs == connection_kwargs
def test_multiple_connections(self, master_host):
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(connection_kwargs=connection_kwargs)
c1 = pool.get_connection('_')
c2 = pool.get_connection('_')
@@ -118,7 +119,7 @@ class TestBlockingConnectionPool:
def test_connection_pool_blocks_until_timeout(self, master_host):
"When out of connections, block for timeout seconds, then raise"
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(max_connections=1, timeout=0.1,
connection_kwargs=connection_kwargs)
pool.get_connection('_')
@@ -134,7 +135,7 @@ class TestBlockingConnectionPool:
When out of connections, block until another connection is released
to the pool
"""
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(max_connections=1, timeout=2,
connection_kwargs=connection_kwargs)
c1 = pool.get_connection('_')
@@ -149,7 +150,7 @@ class TestBlockingConnectionPool:
assert time.time() - start >= 0.1
def test_reuse_previously_released_connection(self, master_host):
- connection_kwargs = {'host': master_host}
+ connection_kwargs = {'host': master_host[0], 'port': master_host[1]}
pool = self.get_pool(connection_kwargs=connection_kwargs)
c1 = pool.get_connection('_')
pool.release(c1)
diff --git a/tests/test_multiprocessing.py b/tests/test_multiprocessing.py
index 2d27c4e..d0feef1 100644
--- a/tests/test_multiprocessing.py
+++ b/tests/test_multiprocessing.py
@@ -35,7 +35,7 @@ class TestMultiprocessing:
A connection owned by a parent and closed by a child doesn't
destroy the file descriptors so a parent can still use it.
"""
- conn = Connection(host=master_host)
+ conn = Connection(host=master_host[0], port=master_host[1])
conn.send_command('ping')
assert conn.read_response() == b'PONG'
@@ -61,7 +61,7 @@ class TestMultiprocessing:
A connection owned by a parent is unusable by a child if the parent
(the owning process) closes the connection.
"""
- conn = Connection(host=master_host)
+ conn = Connection(host=master_host[0], port=master_host[1])
conn.send_command('ping')
assert conn.read_response() == b'PONG'
@@ -89,7 +89,9 @@ class TestMultiprocessing:
A child will create its own connections when using a pool created
by a parent.
"""
- pool = ConnectionPool.from_url('redis://{}'.format(master_host),
+ pool = ConnectionPool.from_url('redis://{}:{}'.format(master_host[0],
+ master_host[1],
+ ),
max_connections=max_connections)
conn = pool.get_connection('ping')
@@ -124,7 +126,8 @@ class TestMultiprocessing:
A child process that uses the same pool as its parent isn't affected
when the parent disconnects all connections within the pool.
"""
- pool = ConnectionPool.from_url('redis://{}'.format(master_host),
+ pool = ConnectionPool.from_url('redis://{}:{}'.format(master_host[0],
+ master_host[1]),
max_connections=max_connections)
conn = pool.get_connection('ping')
diff --git a/tests/test_sentinel.py b/tests/test_sentinel.py
index 54cf262..7f3ff0a 100644
--- a/tests/test_sentinel.py
+++ b/tests/test_sentinel.py
@@ -10,7 +10,7 @@ import redis.sentinel
@pytest.fixture(scope="module")
def master_ip(master_host):
- yield socket.gethostbyname(master_host)
+ yield socket.gethostbyname(master_host[0])
class SentinelTestClient: