-
Notifications
You must be signed in to change notification settings - Fork 140
Closed
Labels
Description
Test Name
TestClusterRoutes.test_zscan & TestClusterRoutes.test_sync_zscan
Test Location
tests/async_tests/test_async_client.py:10278: AssertionError
Failure Permlink
https://github.com/valkey-io/valkey-glide/actions/runs/19090220028/job/54539175508#step:9:5368
Frequency
No response
Steps to Reproduce
No response
System Information
aarch64-unknown-linux-gnu
Language and Version
Python 3.12
Engine Version
8.1
Logs
_______ TestClusterRoutes.test_zscan[asyncio-ProtocolVersion.RESP2-True] _______
self = <test_async_client.TestClusterRoutes object at 0xfbcb7d7ff020>
glide_client = <glide.glide_client.GlideClusterClient object at 0xfbcb7714ecf0>
@pytest.mark.parametrize("cluster_mode", [True, False])
@pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3])
async def test_zscan(self, glide_client: GlideClusterClient):
key1 = f"{{key}}-1{get_random_string(5)}"
key2 = f"{{key}}-2{get_random_string(5)}"
initial_cursor = "0"
result_cursor_index = 0
result_collection_index = 1
default_count = 20
num_map: Dict[TEncodable, float] = {}
num_map_with_str_scores = {}
for i in range(50000): # Use large dataset to force an iterative cursor.
num_map.update({"value " + str(i): i})
num_map_with_str_scores.update({"value " + str(i): str(i)})
char_map: Mapping[TEncodable, float] = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4}
char_map_with_str_scores = {
"a": "0",
"b": "1",
"c": "2",
"d": "3",
"e": "4",
}
def convert_list_to_dict(list: List) -> dict:
return {list[i]: list[i + 1] for i in range(0, len(list), 2)}
# Empty set
result = await glide_client.zscan(key1, initial_cursor)
assert result[result_cursor_index] == initial_cursor.encode()
assert result[result_collection_index] == []
# Negative cursor
if await check_if_server_version_lt(glide_client, "8.0.0"):
result = await glide_client.zscan(key1, "-1")
assert result[result_cursor_index] == initial_cursor.encode()
assert result[result_collection_index] == []
else:
with pytest.raises(RequestError):
await glide_client.zscan(key2, "-1")
# Result contains the whole set
assert await glide_client.zadd(key1, char_map) == len(char_map)
result = await glide_client.zscan(key1, initial_cursor)
result_collection = result[result_collection_index]
assert result[result_cursor_index] == initial_cursor.encode()
assert len(result_collection) == len(char_map) * 2
assert convert_list_to_dict(result_collection) == cast(
list, convert_string_to_bytes_object(char_map_with_str_scores)
)
result = await glide_client.zscan(key1, initial_cursor, match="a")
result_collection = result[result_collection_index]
assert result[result_cursor_index] == initial_cursor.encode()
assert convert_list_to_dict(result_collection) == {b"a": b"0"}
# Result contains a subset of the key
assert await glide_client.zadd(key1, num_map) == len(num_map)
full_result_map = {}
result = result = cast(
list,
convert_bytes_to_string_object(
await glide_client.zscan(key1, initial_cursor)
),
)
result_cursor = str(result[result_cursor_index])
result_iteration_collection: Dict[str, str] = convert_list_to_dict(
result[result_collection_index]
)
full_result_map.update(result_iteration_collection)
# 0 is returned for the cursor of the last iteration.
while result_cursor != "0":
next_result = cast(
list,
convert_bytes_to_string_object(
await glide_client.zscan(key1, result_cursor)
),
)
next_result_cursor = next_result[result_cursor_index]
assert next_result_cursor != result_cursor
next_result_collection = convert_list_to_dict(
next_result[result_collection_index]
)
assert result_iteration_collection != next_result_collection
full_result_map.update(next_result_collection)
result_iteration_collection = next_result_collection
result_cursor = next_result_cursor
num_map_with_str_scores.update(char_map_with_str_scores)
assert num_map_with_str_scores == full_result_map
# Test match pattern
result = await glide_client.zscan(key1, initial_cursor, match="*")
assert result[result_cursor_index] != b"0"
assert len(result[result_collection_index]) >= default_count
# Test count
result = await glide_client.zscan(key1, initial_cursor, count=20)
assert result[result_cursor_index] != b"0"
assert len(result[result_collection_index]) >= 20
# Test count with match returns a non-empty list
result = await glide_client.zscan(key1, initial_cursor, match="1*", count=20)
assert result[result_cursor_index] != b"0"
assert len(result[result_collection_index]) >= 0
# Test no_scores option
if not await check_if_server_version_lt(glide_client, "8.0.0"):
result = await glide_client.zscan(key1, initial_cursor, no_scores=True)
assert result[result_cursor_index] != b"0"
values_array = cast(List[bytes], result[result_collection_index])
# Verify that scores are not included
> assert all(
item.startswith(b"value") and item.isascii() for item in values_array
)
E assert False
E + where False = all(<generator object TestClusterRoutes.test_zscan.<locals>.<genexpr> at 0xfbcb7cd2fac0>)
tests/async_tests/test_async_client.py:10278: AssertionError
Screenshots
No response
Glide Version
No response
Expected Behavior
No response
Actual Behavior
No response
Possible Fixes
No response
Reactions are currently unavailable