Skip to content

Commit 29da9b9

Browse files
committed
add test for setting ttl
1 parent 69407f6 commit 29da9b9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/integration/test_async_search_index.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,26 @@ async def test_async_search_index_connect(index_schema, redis_url):
707707
await async_index.connect(redis_url=redis_url)
708708
assert async_index.client is not None
709709
await async_index.disconnect()
710+
711+
712+
@pytest.mark.asyncio
713+
@pytest.mark.parametrize("ttl", [None, 30])
714+
async def test_search_index_load_with_ttl(async_index, ttl):
715+
"""Test that TTL is correctly set on keys when using load() with ttl parameter."""
716+
await async_index.create(overwrite=True, drop=True)
717+
718+
# Load test data with TTL parameter
719+
data = [{"id": "1", "test": "foo"}]
720+
keys = await async_index.load(data, id_field="id", ttl=ttl)
721+
722+
# Check TTL on the loaded key
723+
client = await async_index._get_client()
724+
key_ttl = await client.ttl(keys[0])
725+
726+
if ttl is None:
727+
# No TTL set, should return -1
728+
assert key_ttl == -1
729+
else:
730+
# TTL should be set and close to the expected value
731+
assert key_ttl > 0
732+
assert abs(key_ttl - ttl) <= 5

tests/integration/test_search_index.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,3 +697,24 @@ def test_search_index_validates_query_with_hnsw_algorithm(hnsw_index, sample_dat
697697
)
698698
# Should not raise
699699
hnsw_index.query(query)
700+
701+
702+
@pytest.mark.parametrize("ttl", [None, 30])
703+
def test_search_index_load_with_ttl(index, ttl):
704+
"""Test that TTL is correctly set on keys when using load() with ttl parameter."""
705+
index.create(overwrite=True, drop=True)
706+
707+
# Load test data with TTL parameter
708+
data = [{"id": "1", "test": "foo"}]
709+
keys = index.load(data, id_field="id", ttl=ttl)
710+
711+
# Check TTL on the loaded key
712+
key_ttl = index.client.ttl(keys[0])
713+
714+
if ttl is None:
715+
# No TTL set, should return -1
716+
assert key_ttl == -1
717+
else:
718+
# TTL should be set and close to the expected value
719+
assert key_ttl > 0
720+
assert abs(key_ttl - ttl) <= 5

0 commit comments

Comments
 (0)