55from time import sleep
66
77import pytest
8+ from tenacity import Retrying , stop_after_delay , wait_fixed
89
910from langfuse import Langfuse , propagate_attributes
1011from langfuse ._client .resource_manager import LangfuseResourceManager
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
2029async 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
382393def test_create_score_with_custom_timestamp ():
0 commit comments