Skip to content

Commit

Permalink
Fixes to allow --redis-url to pass through all tests (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim committed Nov 11, 2021
1 parent ec172e7 commit 6a293e6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 16 deletions.
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def pytest_addoption(parser):
def _get_info(redis_url):
client = redis.Redis.from_url(redis_url)
info = client.info()
try:
client.execute_command("CONFIG SET maxmemory 5555555")
client.execute_command("CONFIG SET maxmemory 0")
info["enterprise"] = False
except redis.exceptions.ResponseError:
info["enterprise"] = True
client.connection_pool.disconnect()
return info

Expand All @@ -42,6 +48,7 @@ def pytest_sessionstart(session):
arch_bits = info["arch_bits"]
REDIS_INFO["version"] = version
REDIS_INFO["arch_bits"] = arch_bits
REDIS_INFO["enterprise"] = info["enterprise"]

# module info, if the second redis is running
try:
Expand Down Expand Up @@ -92,6 +99,17 @@ def skip_ifmodversion_lt(min_version: str, module_name: str):
raise AttributeError("No redis module named {}".format(module_name))


def skip_if_redis_enterprise(func):
check = REDIS_INFO["enterprise"] is True
return pytest.mark.skipif(check, reason="Redis enterprise"
)


def skip_ifnot_redis_enterprise(func):
check = REDIS_INFO["enterprise"] is False
return pytest.mark.skipif(check, reason="Redis enterprise")


def _get_client(cls, request, single_connection_client=True, flushdb=True,
from_url=None,
**kwargs):
Expand Down
50 changes: 38 additions & 12 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
_get_client,
skip_if_server_version_gte,
skip_if_server_version_lt,
skip_if_redis_enterprise,
skip_unless_arch_bits,
)

Expand Down Expand Up @@ -80,6 +81,7 @@ def test_acl_cat_with_category(self, r):
assert 'get' in commands

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_deluser(self, r, request):
username = 'redis-py-user'

Expand All @@ -104,6 +106,7 @@ def teardown():
assert r.acl_getuser(users[4]) is None

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_genpass(self, r):
password = r.acl_genpass()
assert isinstance(password, str)
Expand All @@ -117,6 +120,7 @@ def test_acl_genpass(self, r):
assert isinstance(password, str)

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_getuser_setuser(self, r, request):
username = 'redis-py-user'

Expand Down Expand Up @@ -210,6 +214,7 @@ def test_acl_help(self, r):
assert len(res) != 0

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_list(self, r, request):
username = 'redis-py-user'

Expand All @@ -222,6 +227,7 @@ def teardown():
assert len(users) == 2

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_log(self, r, request):
username = 'redis-py-user'

Expand Down Expand Up @@ -257,6 +263,7 @@ def teardown():
assert r.acl_log_reset()

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_setuser_categories_without_prefix_fails(self, r, request):
username = 'redis-py-user'

Expand All @@ -268,6 +275,7 @@ def teardown():
r.acl_setuser(username, categories=['list'])

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_setuser_commands_without_prefix_fails(self, r, request):
username = 'redis-py-user'

Expand All @@ -279,6 +287,7 @@ def teardown():
r.acl_setuser(username, commands=['get'])

@skip_if_server_version_lt("6.0.0")
@skip_if_redis_enterprise
def test_acl_setuser_add_passwords_and_nopass_fails(self, r, request):
username = 'redis-py-user'

Expand Down Expand Up @@ -312,13 +321,18 @@ def test_client_info(self, r):
assert 'addr' in info

@skip_if_server_version_lt('5.0.0')
def test_client_list_type(self, r):
def test_client_list_types_not_replica(self, r):
with pytest.raises(exceptions.RedisError):
r.client_list(_type='not a client type')
for client_type in ['normal', 'master', 'replica', 'pubsub']:
for client_type in ['normal', 'master', 'pubsub']:
clients = r.client_list(_type=client_type)
assert isinstance(clients, list)

@skip_if_redis_enterprise
def test_client_list_replica(self, r):
clients = r.client_list(_type='replica')
assert isinstance(clients, list)

@skip_if_server_version_lt('6.2.0')
def test_client_list_client_id(self, r, request):
clients = r.client_list()
Expand Down Expand Up @@ -454,6 +468,7 @@ def test_client_kill_filter_by_laddr(self, r, r2):
assert r.client_kill_filter(laddr=client_2_addr)

@skip_if_server_version_lt('6.0.0')
@skip_if_redis_enterprise
def test_client_kill_filter_by_user(self, r, request):
killuser = 'user_to_kill'
r.acl_setuser(killuser, enabled=True, reset=True,
Expand All @@ -467,13 +482,15 @@ def test_client_kill_filter_by_user(self, r, request):
r.acl_deluser(killuser)

@skip_if_server_version_lt('2.9.50')
@skip_if_redis_enterprise
def test_client_pause(self, r):
assert r.client_pause(1)
assert r.client_pause(timeout=1)
with pytest.raises(exceptions.RedisError):
r.client_pause(timeout='not an integer')

@skip_if_server_version_lt('6.2.0')
@skip_if_redis_enterprise
def test_client_unpause(self, r):
assert r.client_unpause() == b'OK'

Expand All @@ -491,15 +508,18 @@ def test_client_reply(self, r, r_timeout):
assert r.get('foo') == b'bar'

@skip_if_server_version_lt('6.0.0')
@skip_if_redis_enterprise
def test_client_getredir(self, r):
assert isinstance(r.client_getredir(), int)
assert r.client_getredir() == -1

def test_config_get(self, r):
data = r.config_get()
assert 'maxmemory' in data
assert data['maxmemory'].isdigit()
assert len(data.keys()) > 10
# # assert 'maxmemory' in data
# assert data['maxmemory'].isdigit()

@skip_if_redis_enterprise
def test_config_resetstat(self, r):
r.ping()
prior_commands_processed = int(r.info()['total_commands_processed'])
Expand All @@ -508,14 +528,12 @@ def test_config_resetstat(self, r):
reset_commands_processed = int(r.info()['total_commands_processed'])
assert reset_commands_processed < prior_commands_processed

@skip_if_redis_enterprise
def test_config_set(self, r):
data = r.config_get()
rdbname = data['dbfilename']
try:
assert r.config_set('dbfilename', 'redis_py_test.rdb')
assert r.config_get()['dbfilename'] == 'redis_py_test.rdb'
finally:
assert r.config_set('dbfilename', rdbname)
r.config_set('timeout', 70)
assert r.config_get()['timeout'] == '70'
assert r.config_set('timeout', 0)
assert r.config_get()['timeout'] == '0'

def test_dbsize(self, r):
r['a'] = 'foo'
Expand All @@ -530,8 +548,10 @@ def test_info(self, r):
r['b'] = 'bar'
info = r.info()
assert isinstance(info, dict)
assert info['db9']['keys'] == 2
assert 'arch_bits' in info.keys()
assert 'redis_version' in info.keys()

@skip_if_redis_enterprise
def test_lastsave(self, r):
assert isinstance(r.lastsave(), datetime.datetime)

Expand Down Expand Up @@ -625,6 +645,7 @@ def test_time(self, r):
assert isinstance(t[0], int)
assert isinstance(t[1], int)

@skip_if_redis_enterprise
def test_bgsave(self, r):
assert r.bgsave()
time.sleep(0.3)
Expand Down Expand Up @@ -2433,6 +2454,7 @@ def test_cluster_slaves(self, mock_cluster_resp_slaves):
'slaves', 'nodeid'), dict)

@skip_if_server_version_lt('3.0.0')
@skip_if_redis_enterprise
def test_readwrite(self, r):
assert r.readwrite()

Expand Down Expand Up @@ -3614,6 +3636,7 @@ def test_memory_usage(self, r):
assert isinstance(r.memory_usage('foo'), int)

@skip_if_server_version_lt('4.0.0')
@skip_if_redis_enterprise
def test_module_list(self, r):
assert isinstance(r.module_list(), list)
for x in r.module_list():
Expand All @@ -3626,6 +3649,7 @@ def test_command_count(self, r):
assert res >= 100

@skip_if_server_version_lt('4.0.0')
@skip_if_redis_enterprise
def test_module(self, r):
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
r.module_load('/some/fake/path')
Expand Down Expand Up @@ -3680,6 +3704,7 @@ def test_restore_frequency(self, r):
assert r.get(key) == b'blee!'

@skip_if_server_version_lt('5.0.0')
@skip_if_redis_enterprise
def test_replicaof(self, r):
with pytest.raises(redis.ResponseError):
assert r.replicaof("NO ONE")
Expand Down Expand Up @@ -3756,6 +3781,7 @@ def test_22_info(self, r):
assert '6' in parsed['allocation_stats']
assert '>=256' in parsed['allocation_stats']

@skip_if_redis_enterprise
def test_large_responses(self, r):
"The PythonParser has some special cases for return values > 1MB"
# load up 5MB of data into a key
Expand Down
12 changes: 11 additions & 1 deletion tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

from threading import Thread
from redis.connection import ssl_available, to_bool
from .conftest import skip_if_server_version_lt, _get_client
from .conftest import (
skip_if_server_version_lt,
skip_if_redis_enterprise,
_get_client
)
from .test_pubsub import wait_for_message


Expand Down Expand Up @@ -481,6 +485,7 @@ def test_on_connect_error(self):
assert not pool._available_connections[0]._sock

@skip_if_server_version_lt('2.8.8')
@skip_if_redis_enterprise
def test_busy_loading_disconnects_socket(self, r):
"""
If Redis raises a LOADING error, the connection should be
Expand All @@ -491,6 +496,7 @@ def test_busy_loading_disconnects_socket(self, r):
assert not r.connection._sock

@skip_if_server_version_lt('2.8.8')
@skip_if_redis_enterprise
def test_busy_loading_from_pipeline_immediate_command(self, r):
"""
BusyLoadingErrors should raise from Pipelines that execute a
Expand All @@ -506,6 +512,7 @@ def test_busy_loading_from_pipeline_immediate_command(self, r):
assert not pool._available_connections[0]._sock

@skip_if_server_version_lt('2.8.8')
@skip_if_redis_enterprise
def test_busy_loading_from_pipeline(self, r):
"""
BusyLoadingErrors should be raised from a pipeline execution
Expand All @@ -521,6 +528,7 @@ def test_busy_loading_from_pipeline(self, r):
assert not pool._available_connections[0]._sock

@skip_if_server_version_lt('2.8.8')
@skip_if_redis_enterprise
def test_read_only_error(self, r):
"READONLY errors get turned in ReadOnlyError exceptions"
with pytest.raises(redis.ReadOnlyError):
Expand All @@ -546,6 +554,7 @@ def test_connect_from_url_unix(self):
'path=/path/to/socket,db=0',
)

@skip_if_redis_enterprise
def test_connect_no_auth_supplied_when_required(self, r):
"""
AuthenticationError should be raised when the server requires a
Expand All @@ -555,6 +564,7 @@ def test_connect_no_auth_supplied_when_required(self, r):
r.execute_command('DEBUG', 'ERROR',
'ERR Client sent AUTH, but no password is set')

@skip_if_redis_enterprise
def test_connect_invalid_password_supplied(self, r):
"AuthenticationError should be raised when sending the wrong password"
with pytest.raises(redis.AuthenticationError):
Expand Down
15 changes: 14 additions & 1 deletion tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .conftest import wait_for_command
from .conftest import (
skip_if_redis_enterprise,
skip_ifnot_redis_enterprise,
wait_for_command
)


class TestMonitor:
Expand Down Expand Up @@ -40,6 +44,7 @@ def test_command_with_escaped_data(self, r):
response = wait_for_command(r, m, 'GET foo\\\\x92')
assert response['command'] == 'GET foo\\\\x92'

@skip_if_redis_enterprise
def test_lua_script(self, r):
with r.monitor() as m:
script = 'return redis.call("GET", "foo")'
Expand All @@ -49,3 +54,11 @@ def test_lua_script(self, r):
assert response['client_type'] == 'lua'
assert response['client_address'] == 'lua'
assert response['client_port'] == ''

@skip_ifnot_redis_enterprise
def test_lua_script_in_enterprise(self, r):
with r.monitor() as m:
script = 'return redis.call("GET", "foo")'
assert r.eval(script, 0) is None
response = wait_for_command(r, m, 'GET foo')
assert response is None
7 changes: 6 additions & 1 deletion tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import redis
from redis.exceptions import ConnectionError

from .conftest import _get_client, skip_if_server_version_lt
from .conftest import (
_get_client,
skip_if_redis_enterprise,
skip_if_server_version_lt
)


def wait_for_message(pubsub, timeout=0.1, ignore_subscribe_messages=False):
Expand Down Expand Up @@ -528,6 +532,7 @@ def test_send_pubsub_ping_message(self, r):
class TestPubSubConnectionKilled:

@skip_if_server_version_lt('3.0.0')
@skip_if_redis_enterprise
def test_connection_error_raised_when_connection_dies(self, r):
p = r.pubsub()
p.subscribe('foo')
Expand Down
Loading

0 comments on commit 6a293e6

Please sign in to comment.