From cc027a2b904cd83e186d86b4e08eaaa383426d92 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Sun, 15 Mar 2026 20:25:11 -0700 Subject: [PATCH] Fix flaky test_langsmith_queue_logging: poll instead of fixed sleep The test waited a fixed 3s for async callbacks to populate log_queue. Under xdist -n 4, CPU contention can delay the GLOBAL_LOGGING_WORKER background task beyond 3s. Replace fixed sleeps with polling loops (up to 10s) that break as soon as the expected condition is met. Co-Authored-By: Claude Opus 4.6 --- .../test_langsmith_unit_test.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/logging_callback_tests/test_langsmith_unit_test.py b/tests/logging_callback_tests/test_langsmith_unit_test.py index 17b854b52f..c7b77f2826 100644 --- a/tests/logging_callback_tests/test_langsmith_unit_test.py +++ b/tests/logging_callback_tests/test_langsmith_unit_test.py @@ -475,7 +475,11 @@ async def test_langsmith_queue_logging(): mock_response="This is a mock response", ) - await asyncio.sleep(3) + # Poll for async callbacks to complete (up to 10s) + for _ in range(20): + if len(test_langsmith_logger.log_queue) >= 5: + break + await asyncio.sleep(0.5) # Check that logs are in the queue assert len(test_langsmith_logger.log_queue) == 5 @@ -490,8 +494,11 @@ async def test_langsmith_queue_logging(): mock_response="This is a mock response", ) - # Wait a short time for any asynchronous operations to complete - await asyncio.sleep(1) + # Poll for flush to complete (up to 10s) + for _ in range(20): + if len(test_langsmith_logger.log_queue) < 5: + break + await asyncio.sleep(0.5) print( "Length of langsmith log queue: {}".format(