Skip to content

Commit 71ea926

Browse files
committed
test_no_duplicate_spend_logs
1 parent ca72411 commit 71ea926

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/test_litellm/responses/test_no_duplicate_spend_logs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
the logging object before passing kwargs to internal acompletion() calls,
66
causing duplicate spend log entries for non-OpenAI providers.
77
"""
8-
import sys
8+
import asyncio
99
import os
10+
import sys
11+
1012
import pytest
1113

1214
sys.path.insert(
@@ -26,6 +28,7 @@ def test_logging_object_not_popped():
2628
spend logs for non-OpenAI providers.
2729
"""
2830
import inspect
31+
2932
from litellm.responses import main as responses_module
3033

3134
# Get the source code of the responses function
@@ -84,9 +87,11 @@ async def async_log_success_event(self, kwargs, response_obj, start_time, end_ti
8487
)
8588

8689
# Wait for async logging to complete using the logging worker's flush method
87-
# This is more reliable than sleep() which can cause race conditions
90+
# Then add a small delay to ensure callbacks finish executing
8891
from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER
8992
await GLOBAL_LOGGING_WORKER.flush()
93+
# flush() empties the queue but callbacks may still be running
94+
await asyncio.sleep(0.5)
9095

9196
# Verify that log_success_event was called exactly once
9297
assert spend_logger.log_count == 1, (

0 commit comments

Comments
 (0)