Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redis 7.2.0 tests #2902

Merged
merged 6 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class AbstractRedisCluster:
"READONLY",
"CLUSTER INFO",
"CLUSTER MEET",
"CLUSTER MYSHARDID",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this command implemented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

def cluster_myshardid(self, target_nodes=None):

"CLUSTER NODES",
"CLUSTER REPLICAS",
"CLUSTER RESET",
Expand Down
32 changes: 12 additions & 20 deletions tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,6 @@ async def test_client_no_touch(self, r: redis.Redis):
with pytest.raises(TypeError):
await r.client_no_touch()

@skip_if_server_version_lt("7.2.0")
@pytest.mark.onlycluster
async def test_waitaof(self, r):
# must return a list of 2 elements
assert len(await r.waitaof(0, 0, 0)) == 2
assert len(await r.waitaof(1, 0, 0)) == 2
assert len(await r.waitaof(1, 0, 1000)) == 2

# value is out of range, value must between 0 and 1
with pytest.raises(exceptions.ResponseError):
await r.waitaof(2, 0, 0)
with pytest.raises(exceptions.ResponseError):
await r.waitaof(-1, 0, 0)

async def test_config_get(self, r: redis.Redis):
data = await r.config_get()
assert "maxmemory" in data
Expand Down Expand Up @@ -1821,9 +1807,11 @@ async def test_zrank(self, r: redis.Redis):
async def test_zrank_withscore(self, r: redis.Redis):
await r.zadd("a", {"a1": 1, "a2": 2, "a3": 3, "a4": 4, "a5": 5})
assert await r.zrank("a", "a1") == 0
assert await r.rank("a", "a2") == 1
assert await r.zrank("a", "a2") == 1
assert await r.zrank("a", "a6") is None
assert await r.zrank("a", "a3", withscore=True) == [2, "3"]
assert_resp_response(
r, await r.zrank("a", "a3", withscore=True), [2, b"3"], [2, 3.0]
)
assert await r.zrank("a", "a6", withscore=True) is None

async def test_zrem(self, r: redis.Redis):
Expand Down Expand Up @@ -1920,7 +1908,9 @@ async def test_zrevrank_withscore(self, r: redis.Redis):
assert await r.zrevrank("a", "a1") == 4
assert await r.zrevrank("a", "a2") == 3
assert await r.zrevrank("a", "a6") is None
assert await r.zrevrank("a", "a3", withscore=True) == [2, "3"]
assert_resp_response(
r, await r.zrevrank("a", "a3", withscore=True), [2, b"3"], [2, 3.0]
)
assert await r.zrevrank("a", "a6", withscore=True) is None

async def test_zscore(self, r: redis.Redis):
Expand Down Expand Up @@ -2877,13 +2867,15 @@ async def test_xinfo_consumers(self, r: redis.Redis):
info = await r.xinfo_consumers(stream, group)
assert len(info) == 2
expected = [
{"name": consumer1.encode(), "pending": 1, "inactive": 2},
{"name": consumer2.encode(), "pending": 2, "inactive": 2},
{"name": consumer1.encode(), "pending": 1},
{"name": consumer2.encode(), "pending": 2},
]

# we can't determine the idle time, so just make sure it's an int
# we can't determine the idle and inactive time, so just make sure it's an int
assert isinstance(info[0].pop("idle"), int)
assert isinstance(info[1].pop("idle"), int)
assert isinstance(info[0].pop("inactive"), int)
assert isinstance(info[1].pop("inactive"), int)
assert info == expected

@skip_if_server_version_lt("5.0.0")
Expand Down
30 changes: 10 additions & 20 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,20 +745,6 @@ def test_client_no_touch(self, r):
with pytest.raises(TypeError):
r.client_no_touch()

@pytest.mark.onlycluster
@skip_if_server_version_lt("7.2.0")
def test_waitaof(self, r):
# must return a list of 2 elements
assert len(r.waitaof(0, 0, 0)) == 2
assert len(r.waitaof(1, 0, 0)) == 2
assert len(r.waitaof(1, 0, 1000)) == 2

# value is out of range, value must between 0 and 1
with pytest.raises(exceptions.ResponseError):
r.waitaof(2, 0, 0)
with pytest.raises(exceptions.ResponseError):
r.waitaof(-1, 0, 0)

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("3.2.0")
def test_client_reply(self, r, r_timeout):
Expand Down Expand Up @@ -2854,9 +2840,9 @@ def test_zrank(self, r):
def test_zrank_withscore(self, r: redis.Redis):
r.zadd("a", {"a1": 1, "a2": 2, "a3": 3, "a4": 4, "a5": 5})
assert r.zrank("a", "a1") == 0
assert r.rank("a", "a2") == 1
assert r.zrank("a", "a2") == 1
assert r.zrank("a", "a6") is None
assert r.zrank("a", "a3", withscore=True) == [2, "3"]
assert_resp_response(r, r.zrank("a", "a3", withscore=True), [2, b"3"], [2, 3.0])
assert r.zrank("a", "a6", withscore=True) is None

def test_zrem(self, r):
Expand Down Expand Up @@ -2951,7 +2937,9 @@ def test_zrevrank_withscore(self, r):
assert r.zrevrank("a", "a1") == 4
assert r.zrevrank("a", "a2") == 3
assert r.zrevrank("a", "a6") is None
assert r.zrevrank("a", "a3", withscore=True) == [2, "3"]
assert_resp_response(
r, r.zrevrank("a", "a3", withscore=True), [2, b"3"], [2, 3.0]
)
assert r.zrevrank("a", "a6", withscore=True) is None

def test_zscore(self, r):
Expand Down Expand Up @@ -4404,13 +4392,15 @@ def test_xinfo_consumers(self, r):
info = r.xinfo_consumers(stream, group)
assert len(info) == 2
expected = [
{"name": consumer1.encode(), "pending": 1, "inactive": 2},
{"name": consumer2.encode(), "pending": 2, "inactive": 2},
{"name": consumer1.encode(), "pending": 1},
{"name": consumer2.encode(), "pending": 2},
]

# we can't determine the idle time, so just make sure it's an int
# we can't determine the idle and inactive time, so just make sure it's an int
assert isinstance(info[0].pop("idle"), int)
assert isinstance(info[1].pop("idle"), int)
assert isinstance(info[0].pop("inactive"), int)
assert isinstance(info[1].pop("inactive"), int)
assert info == expected

@skip_if_server_version_lt("7.0.0")
Expand Down