Skip to content

Commit 7e9c513

Browse files
committed
Updated the AnyIO tests based on updated asyncio tests
1 parent 845ffb9 commit 7e9c513

File tree

4 files changed

+79
-11
lines changed

4 files changed

+79
-11
lines changed

tests/test_anyio/test_bloom.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,34 @@ async def test_topk(decoded_r: redis.Redis):
334334
assert 0.9 == round(float(info["decay"]), 1)
335335

336336

337+
@pytest.mark.redismod
338+
async def test_topk_list_with_special_words(decoded_r: redis.Redis):
339+
# test list with empty buckets
340+
assert await decoded_r.topk().reserve("topklist:specialwords", 5, 20, 4, 0.9)
341+
assert await decoded_r.topk().add(
342+
"topklist:specialwords",
343+
"infinity",
344+
"B",
345+
"nan",
346+
"D",
347+
"-infinity",
348+
"infinity",
349+
"infinity",
350+
"B",
351+
"nan",
352+
"G",
353+
"D",
354+
"B",
355+
"D",
356+
"infinity",
357+
"-infinity",
358+
"-infinity",
359+
)
360+
assert ["infinity", "B", "D", "-infinity", "nan"] == await decoded_r.topk().list(
361+
"topklist:specialwords"
362+
)
363+
364+
337365
@pytest.mark.redismod
338366
async def test_topk_incrby(decoded_r: redis.Redis):
339367
await decoded_r.flushdb()

tests/test_anyio/test_cluster.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
if sys.version_info < (3, 11):
5858
from exceptiongroup import ExceptionGroup
5959

60-
pytestmark = [pytest.mark.anyio, pytest.mark.onlycluster]
60+
pytestmark = [pytest.mark.onlycluster, pytest.mark.anyio]
6161

6262

6363
default_host = "127.0.0.1"
@@ -67,12 +67,6 @@
6767
[8192, 16383, ["127.0.0.1", 7001, "node_1"], ["127.0.0.1", 7002, "node_2"]],
6868
]
6969

70-
@pytest.fixture(autouse=True)
71-
def run_gc():
72-
import gc
73-
74-
yield
75-
gc.collect()
7670

7771
class NodeProxy:
7872
"""A class to proxy a node connection to a different port"""

tests/test_anyio/test_search.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ async def decoded_r(create_redis, stack_url):
5151
async def waitForIndex(env, idx, timeout=None):
5252
delay = 0.1
5353
while True:
54-
res = await env.execute_command("FT.INFO", idx)
5554
try:
55+
res = await env.execute_command("FT.INFO", idx)
5656
if int(res[res.index("indexing") + 1]) == 0:
5757
break
5858
except ValueError:
@@ -64,7 +64,7 @@ async def waitForIndex(env, idx, timeout=None):
6464
except ValueError:
6565
break
6666

67-
time.sleep(delay)
67+
await anyio.sleep(delay)
6868
if timeout is not None:
6969
timeout -= delay
7070
if timeout <= 0:
@@ -1767,7 +1767,7 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17671767
mixed_data = {"first_name": "🐍python", "vector_emb": fake_vec.tobytes()}
17681768
await decoded_r.hset(f"{index_name}:1", mapping=mixed_data)
17691769

1770-
schema = (
1770+
schema = [
17711771
TagField("first_name"),
17721772
VectorField(
17731773
"embeddings_bio",
@@ -1778,14 +1778,15 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17781778
"DISTANCE_METRIC": "COSINE",
17791779
},
17801780
),
1781-
)
1781+
]
17821782

17831783
await decoded_r.ft(index_name).create_index(
17841784
fields=schema,
17851785
definition=IndexDefinition(
17861786
prefix=[f"{index_name}:"], index_type=IndexType.HASH
17871787
),
17881788
)
1789+
await waitForIndex(decoded_r, index_name)
17891790

17901791
query = (
17911792
Query("*")
@@ -1795,6 +1796,12 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17951796
result = await decoded_r.ft(index_name).search(query=query, query_params={})
17961797
docs = result.docs
17971798

1799+
if len(docs) == 0:
1800+
hash_content = await decoded_r.hget(f"{index_name}:1", "first_name")
1801+
assert len(docs) > 0, (
1802+
f"Returned search results are empty. Result: {result}; Hash: {hash_content}"
1803+
)
1804+
17981805
decoded_vec_from_search_results = np.frombuffer(
17991806
docs[0]["vector_emb"], dtype=np.float32
18001807
)

tests/test_anyio/test_timeseries.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from tests.conftest import (
77
assert_resp_response,
88
is_resp2_connection,
9+
skip_if_server_version_gte,
10+
skip_if_server_version_lt,
911
skip_ifmodversion_lt,
1012
)
1113

@@ -77,7 +79,24 @@ async def test_alter(decoded_r: redis.Redis):
7779

7880
@pytest.mark.redismod
7981
@skip_ifmodversion_lt("1.4.0", "timeseries")
82+
@skip_if_server_version_lt("7.9.0")
8083
async def test_alter_duplicate_policy(decoded_r: redis.Redis):
84+
assert await decoded_r.ts().create(1)
85+
info = await decoded_r.ts().info(1)
86+
assert_resp_response(
87+
decoded_r, "block", info.get("duplicate_policy"), info.get("duplicatePolicy")
88+
)
89+
assert await decoded_r.ts().alter(1, duplicate_policy="min")
90+
info = await decoded_r.ts().info(1)
91+
assert_resp_response(
92+
decoded_r, "min", info.get("duplicate_policy"), info.get("duplicatePolicy")
93+
)
94+
95+
96+
@pytest.mark.redismod
97+
@skip_ifmodversion_lt("1.4.0", "timeseries")
98+
@skip_if_server_version_gte("7.9.0")
99+
async def test_alter_duplicate_policy_prior_redis_8(decoded_r: redis.Redis):
81100
assert await decoded_r.ts().create(1)
82101
info = await decoded_r.ts().info(1)
83102
assert_resp_response(
@@ -724,7 +743,27 @@ async def test_info(decoded_r: redis.Redis):
724743

725744
@pytest.mark.redismod
726745
@skip_ifmodversion_lt("1.4.0", "timeseries")
746+
@skip_if_server_version_lt("7.9.0")
727747
async def test_info_duplicate_policy(decoded_r: redis.Redis):
748+
await decoded_r.ts().create(
749+
1, retention_msecs=5, labels={"currentLabel": "currentData"}
750+
)
751+
info = await decoded_r.ts().info(1)
752+
assert_resp_response(
753+
decoded_r, "block", info.get("duplicate_policy"), info.get("duplicatePolicy")
754+
)
755+
756+
await decoded_r.ts().create("time-serie-2", duplicate_policy="min")
757+
info = await decoded_r.ts().info("time-serie-2")
758+
assert_resp_response(
759+
decoded_r, "min", info.get("duplicate_policy"), info.get("duplicatePolicy")
760+
)
761+
762+
763+
@pytest.mark.redismod
764+
@skip_ifmodversion_lt("1.4.0", "timeseries")
765+
@skip_if_server_version_gte("7.9.0")
766+
async def test_info_duplicate_policy_prior_redis_8(decoded_r: redis.Redis):
728767
await decoded_r.ts().create(
729768
1, retention_msecs=5, labels={"currentLabel": "currentData"}
730769
)

0 commit comments

Comments
 (0)