Skip to content

Commit 5eec695

Browse files
committed
ci: fix tests by adding dynamic retry
1 parent 19fe363 commit 5eec695

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dev = [
3434
"langgraph>=1,<2",
3535
"autoevals>=0.0.130,<0.1",
3636
"opentelemetry-instrumentation-threading>=0.59b0,<1",
37+
"tenacity>=9.1.4",
3738
]
3839
docs = [
3940
"pdoc>=15.0.4,<16",

tests/test_core_sdk.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from time import sleep
66

77
import pytest
8+
from tenacity import Retrying, stop_after_delay, wait_fixed
89

910
from langfuse import Langfuse, propagate_attributes
1011
from langfuse._client.resource_manager import LangfuseResourceManager
@@ -15,6 +16,14 @@
1516
get_api,
1617
)
1718

19+
LANGFUSE_SECRET_KEY = "sk-lf-04e91827-fcd4-457e-8e51-6cde2417bc67"
20+
LANGFUSE_PUBLIC_KEY = "pk-lf-33e3a6d2-2cac-48f6-8d00-5ccc04cbe804"
21+
LANGFUSE_BASE_URL = "http://localhost:3000"
22+
23+
os.environ["LANGFUSE_SECRET_KEY"] = LANGFUSE_SECRET_KEY
24+
os.environ["LANGFUSE_PUBLIC_KEY"] = LANGFUSE_PUBLIC_KEY
25+
os.environ["LANGFUSE_BASE_URL"] = LANGFUSE_BASE_URL
26+
1827

1928
@pytest.mark.asyncio
2029
async def test_concurrency():
@@ -337,7 +346,6 @@ def test_create_text_score():
337346

338347
# Ensure data is sent
339348
langfuse.flush()
340-
sleep(2)
341349

342350
# Create a text score
343351
score_id = create_uuid()
@@ -360,23 +368,26 @@ def test_create_text_score():
360368

361369
# Ensure data is sent
362370
langfuse.flush()
363-
sleep(2)
364371

365-
# Retrieve and verify
366-
trace = api_wrapper.get_trace(trace_id)
372+
# Retrieve and verify with retry
373+
for attempt in Retrying(
374+
stop=stop_after_delay(10), wait=wait_fixed(0.1), reraise=True
375+
):
376+
with attempt:
377+
trace = api_wrapper.get_trace(trace_id)
367378

368-
# Find the score we created by name
369-
created_score = next(
370-
(s for s in trace["scores"] if s["name"] == "this-is-a-score"), None
371-
)
372-
assert created_score is not None, "Score not found in trace"
373-
assert created_score["id"] == score_id
374-
assert created_score["dataType"] == "TEXT"
375-
assert created_score["value"] is None
376-
assert (
377-
created_score["stringValue"]
378-
== "This is a detailed text evaluation of the output quality."
379-
)
379+
# Find the score we created by name
380+
created_score = next(
381+
(s for s in trace["scores"] if s["name"] == "this-is-a-score"), None
382+
)
383+
assert created_score is not None, "Score not found in trace"
384+
assert created_score["id"] == score_id
385+
assert created_score["dataType"] == "TEXT"
386+
387+
assert (
388+
created_score["stringValue"]
389+
== "This is a detailed text evaluation of the output quality."
390+
)
380391

381392

382393
def test_create_score_with_custom_timestamp():

uv.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)