Skip to content

Commit 1ce809d

Browse files
committed
Add unit tests
1 parent 3bfdd7f commit 1ce809d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/test_asyncio/test_sentinel.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import pytest
55
import pytest_asyncio
6+
from redis.asyncio.client import StrictRedis
7+
68
import redis.asyncio.sentinel
79
from redis import exceptions
810
from redis.asyncio.sentinel import (
@@ -363,3 +365,27 @@ async def test_redis_master_usage(deployed_sentinel):
363365
r = await deployed_sentinel.master_for("redis-py-test", db=0)
364366
await r.set("foo", "bar")
365367
assert (await r.get("foo")) == "bar"
368+
369+
370+
@pytest.mark.onlynoncluster
371+
async def test_sentinel_commands_with_strict_redis_client(request):
372+
sentinel_ips = request.config.getoption("--sentinels")
373+
sentinel_host, sentinel_port = sentinel_ips.split(",")[0].split(":")
374+
protocol = request.config.getoption("--protocol", 2)
375+
376+
client = StrictRedis(
377+
host=sentinel_host, port=sentinel_port, decode_responses=True, protocol=protocol
378+
)
379+
# skipping commands that change the state of the sentinel setup
380+
assert isinstance(
381+
await client.sentinel_get_master_addr_by_name("redis-py-test"), tuple
382+
)
383+
assert isinstance(await client.sentinel_master("redis-py-test"), dict)
384+
assert isinstance(await client.sentinel_masters(), dict)
385+
386+
assert isinstance(await client.sentinel_sentinels("redis-py-test"), list)
387+
assert isinstance(await client.sentinel_slaves("redis-py-test"), list)
388+
389+
assert isinstance(await client.sentinel_ckquorum("redis-py-test"), bool)
390+
391+
await client.close()

tests/test_sentinel.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from unittest import mock
33

44
import pytest
5+
from redis.client import StrictRedis
6+
57
import redis.sentinel
68
from redis import exceptions
79
from redis.sentinel import (
@@ -342,3 +344,25 @@ def test_redis_master_usage(deployed_sentinel):
342344
r = deployed_sentinel.master_for("redis-py-test", db=0)
343345
r.set("foo", "bar")
344346
assert r.get("foo") == "bar"
347+
348+
349+
@pytest.mark.onlynoncluster
350+
def test_sentinel_commands_with_strict_redis_client(request):
351+
sentinel_ips = request.config.getoption("--sentinels")
352+
sentinel_host, sentinel_port = sentinel_ips.split(",")[0].split(":")
353+
protocol = request.config.getoption("--protocol", 2)
354+
355+
client = StrictRedis(
356+
host=sentinel_host, port=sentinel_port, decode_responses=True, protocol=protocol
357+
)
358+
# skipping commands that change the state of the sentinel setup
359+
assert isinstance(client.sentinel_get_master_addr_by_name("redis-py-test"), tuple)
360+
assert isinstance(client.sentinel_master("redis-py-test"), dict)
361+
assert isinstance(client.sentinel_masters(), dict)
362+
363+
assert isinstance(client.sentinel_sentinels("redis-py-test"), list)
364+
assert isinstance(client.sentinel_slaves("redis-py-test"), list)
365+
366+
assert isinstance(client.sentinel_ckquorum("redis-py-test"), bool)
367+
368+
client.close()

0 commit comments

Comments
 (0)