summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2018-12-17 13:12:58 -0800
committerGitHub <noreply@github.com>2018-12-17 13:12:58 -0800
commit655dc94dc5473a9be3cc25cd0f9a827c5ca483a5 (patch)
tree70964de709e1b781d6a43a8ab8df94265d0247c5 /tests
parent59b9cbaa85bce07171b7c0b9fb29ec5ba840fc67 (diff)
parente9e83700cc30ed4ba6f6cf4a96773390ec9d0824 (diff)
downloadredis-py-655dc94dc5473a9be3cc25cd0f9a827c5ca483a5.tar.gz
Merge pull request #1098 from theodesp/client-kill-filter
Add client kill with filter
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py8
-rw-r--r--tests/test_commands.py53
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 5a43968..6e046f2 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -47,6 +47,14 @@ def r(request, **kwargs):
return _get_client(redis.Redis, request, **kwargs)
+@pytest.fixture()
+def r2(request, **kwargs):
+ return [
+ _get_client(redis.Redis, request, **kwargs),
+ _get_client(redis.Redis, request, **kwargs),
+ ]
+
+
def _gen_cluster_mock_resp(r, response):
mock_connection_pool = Mock()
connection = Mock()
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 733ec4f..144b94c 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -96,6 +96,59 @@ class TestRedisCommands(object):
assert r.client_getname() == 'redis_py_test'
@skip_if_server_version_lt('2.6.9')
+ def test_client_kill(self, r, r2):
+ r.client_setname('redis-py-c1')
+ r2[0].client_setname('redis-py-c2')
+ r2[1].client_setname('redis-py-c3')
+ test_clients = [client for client in r.client_list()
+ if client.get('name')
+ in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']]
+ assert len(test_clients) == 3
+
+ resp = r.client_kill(test_clients[1].get('addr'))
+ assert isinstance(resp, bool) and resp is True
+
+ test_clients = [client for client in r.client_list()
+ if client.get('name')
+ in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']]
+ assert len(test_clients) == 2
+
+ @skip_if_server_version_lt('2.8.12')
+ def test_client_kill_filter_invalid_params(self, r):
+ # empty
+ with pytest.raises(exceptions.DataError):
+ r.client_kill_filter()
+
+ # invalid skipme
+ with pytest.raises(exceptions.DataError):
+ r.client_kill_filter(skipme="yeah")
+
+ # invalid type
+ with pytest.raises(exceptions.DataError):
+ r.client_kill_filter(_type="caster")
+
+ @skip_if_server_version_lt('2.8.12')
+ def test_client_kill_filter(self, r, r2):
+ r.client_setname('redis-py-c1')
+ r2[0].client_setname('redis-py-c2')
+ r2[1].client_setname('redis-py-c3')
+ test_clients = [client for client in r.client_list()
+ if client.get('name')
+ in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']]
+ assert len(test_clients) == 3
+
+ resp = r.client_kill_filter(_id=test_clients[1].get('id'))
+ assert isinstance(resp, int) and resp == 1
+
+ resp = r.client_kill_filter(addr=test_clients[2].get('addr'))
+ assert isinstance(resp, int) and resp == 1
+
+ test_clients = [client for client in r.client_list()
+ if client.get('name')
+ in ['redis-py-c1', 'redis-py-c2', 'redis-py-c3']]
+ assert len(test_clients) == 1
+
+ @skip_if_server_version_lt('2.6.9')
def test_client_list_after_client_setname(self, r):
r.client_setname('redis_py_test')
clients = r.client_list()