Skip to content

Commit 127e2f9

Browse files
authored
INTPYTHON-770 Make ttl test more reliable (#224)
1 parent e5a1022 commit 127e2f9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

libs/langgraph-store-mongodb/tests/integration_tests/test_store_semantic_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
DB_NAME = os.environ.get("DB_NAME", "langgraph-test")
2323
COLLECTION_NAME = "semantic_search_async"
2424
INDEX_NAME = "vector_index"
25-
TIMEOUT, INTERVAL = 30, 1 # timeout to index new data
25+
TIMEOUT, INTERVAL = 60, 1 # timeout to index new data
2626

2727
DIMENSIONS = 5 # Dimensions of embedding model
2828

libs/langgraph-store-mongodb/tests/unit_tests/test_store.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import time
23
from collections.abc import Generator
34
from datetime import datetime
45

@@ -180,6 +181,8 @@ def test_ttl() -> None:
180181
res = store.collection.find_one({})
181182
assert res is not None
182183
orig_updated_at = res["updated_at"]
184+
# Add a delay to ensure a different timestamp.
185+
time.sleep(0.1)
183186
res = store.get(namespace=namespace, key=key)
184187
assert res is not None
185188
found = store.collection.find_one({})
@@ -200,6 +203,8 @@ def test_ttl() -> None:
200203
found = store.collection.find_one({})
201204
assert found is not None
202205
orig_updated_at = found["updated_at"]
206+
# Add a delay to ensure a different timestamp.
207+
time.sleep(0.1)
203208
res = store.get(namespace=namespace, key=key)
204209
assert res is not None
205210
found = store.collection.find_one({})
@@ -220,6 +225,8 @@ def test_ttl() -> None:
220225
found = store.collection.find_one({})
221226
assert found is not None
222227
orig_updated_at = found["updated_at"]
228+
# Add a delay to ensure a different timestamp.
229+
time.sleep(0.1)
223230
res = store.get(namespace=namespace, key=key)
224231
assert res is not None
225232
found = store.collection.find_one({})
@@ -240,6 +247,8 @@ def test_ttl() -> None:
240247
found = store.collection.find_one({})
241248
assert found is not None
242249
orig_updated_at = found["updated_at"]
250+
# Add a delay to ensure a different timestamp.
251+
time.sleep(0.1)
243252
res = store.get(refresh_ttl=False, namespace=namespace, key=key)
244253
assert res is not None
245254
found = store.collection.find_one({})

libs/langgraph-store-mongodb/tests/unit_tests/test_store_async.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import os
23
from collections.abc import AsyncGenerator
34
from datetime import datetime
@@ -184,6 +185,8 @@ async def test_ttl() -> None:
184185
res = store.collection.find_one({})
185186
assert res is not None
186187
orig_updated_at = res["updated_at"]
188+
# Add a delay to ensure a different timestamp.
189+
await asyncio.sleep(0.1)
187190
res = await store.aget(namespace=namespace, key=key)
188191
assert res is not None
189192
found = store.collection.find_one({})
@@ -204,6 +207,8 @@ async def test_ttl() -> None:
204207
found = store.collection.find_one({})
205208
assert found is not None
206209
orig_updated_at = found["updated_at"]
210+
# Add a delay to ensure a different timestamp.
211+
await asyncio.sleep(0.1)
207212
res = await store.aget(namespace=namespace, key=key)
208213
assert res is not None
209214
found = store.collection.find_one({})
@@ -224,6 +229,8 @@ async def test_ttl() -> None:
224229
found = store.collection.find_one({})
225230
assert found is not None
226231
orig_updated_at = found["updated_at"]
232+
# Add a delay to ensure a different timestamp.
233+
await asyncio.sleep(0.1)
227234
res = await store.aget(namespace=namespace, key=key)
228235
assert res is not None
229236
found = store.collection.find_one({})
@@ -244,9 +251,11 @@ async def test_ttl() -> None:
244251
found = store.collection.find_one({})
245252
assert found is not None
246253
orig_updated_at = found["updated_at"]
254+
# Add a delay to ensure a different timestamp.
255+
await asyncio.sleep(0.1)
256+
found = store.collection.find_one({})
247257
res = await store.aget(refresh_ttl=False, namespace=namespace, key=key)
248258
assert res is not None
249-
found = store.collection.find_one({})
250259
assert found is not None
251260
new_updated_at = found["updated_at"]
252261
assert new_updated_at == orig_updated_at

0 commit comments

Comments
 (0)