mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-02 06:22:48 +00:00
test_no_duplicate_spend_logs
This commit is contained in:
@@ -5,8 +5,10 @@ This test verifies the fix for issue #15740 where kwargs.pop() was removing
|
||||
the logging object before passing kwargs to internal acompletion() calls,
|
||||
causing duplicate spend log entries for non-OpenAI providers.
|
||||
"""
|
||||
import sys
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(
|
||||
@@ -26,6 +28,7 @@ def test_logging_object_not_popped():
|
||||
spend logs for non-OpenAI providers.
|
||||
"""
|
||||
import inspect
|
||||
|
||||
from litellm.responses import main as responses_module
|
||||
|
||||
# Get the source code of the responses function
|
||||
@@ -84,9 +87,11 @@ async def test_no_duplicate_spend_logs():
|
||||
)
|
||||
|
||||
# Wait for async logging to complete using the logging worker's flush method
|
||||
# This is more reliable than sleep() which can cause race conditions
|
||||
# Then add a small delay to ensure callbacks finish executing
|
||||
from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER
|
||||
await GLOBAL_LOGGING_WORKER.flush()
|
||||
# flush() empties the queue but callbacks may still be running
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
# Verify that log_success_event was called exactly once
|
||||
assert spend_logger.log_count == 1, (
|
||||
|
||||
Reference in New Issue
Block a user