litellm/tests/unit/proxy/utils/proxy_logging
joshua-berri e4759def40
fix(logging): retain streaming success logging tasks until they finish (#52067)
* fix(logging): retain streaming success logging tasks until they finish

Streaming chat, A2A, Gemini/Vertex and the proxy's deferred chat stream
logging scheduled their success dispatch with a bare asyncio.create_task.
The loop only holds weak references to tasks, so a dispatch suspended on
an awaitable nothing else reaches could be garbage collected mid-flight
and its spend log never written. Route them through spawn_logging_task,
which keeps a strong reference until completion, logs failures and is
drained at proxy shutdown.

* test(logging): release parked logging callbacks on every exit path

Wrap the garbage collection regressions in a context manager that releases
the parked callback, waits for its task and drains the logging registry even
when the test fails, assert exactly one parked callback, and leave the
orphaned closure dispatch on its original schedule.

* test(logging): cancel a parked logging callback that never finishes

Cancel and await the parked task if it is still pending after release, fail
the test in that case, and leave the streaming cache write on its original
schedule since it hands off to an already tracked write without suspending.

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-16 11:21:05 -08:00
..
__init__.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
_harness_smoke_test.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
conftest.py test(proxy): delete the legacy proxy test tree and shard tests/unit/proxy by glob (#44018) 2026-10-01 11:40:45 -07:00
test_alerting.py fix(proxy): cooldown errors carry 429, Sentry starts at boot without request bodies, tracing failures log at ERROR, exporter counters exported (#46344) 2026-10-16 00:53:52 +00:00
test_callback_capabilities_class.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
test_callback_capabilities_dataclass.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
test_during_call_hook.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
test_guardrail_pipeline.py fix(guardrails): check a model-level post_call response once across the proxy and deployment layers (#50300) 2026-11-07 07:34:06 +09:00
test_internal_usage_cache.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
test_lifecycle.py fix(proxy): build configured logging callbacks at boot so a broken callback fails startup instead of the first request (#46378) 2026-10-14 16:51:55 +00:00
test_mcp_bridging.py feat(mcp): hand listed-tool description and input schema to pre-call hooks per caller (#41162) 2026-10-04 00:53:58 -07:00
test_module_helpers.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
test_post_call_failure_hook.py fix(proxy): run baggage tag mappings and budget checks on /queue/chat/completions (#51753) 2026-11-14 08:54:54 -05:00
test_post_call_success_hook.py test(proxy): move utils, agent_endpoints and endpoint tests into tests/unit/proxy (#44006) 2026-10-01 11:06:42 -07:00
test_pre_call_hook.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_streaming_hooks.py fix(logging): retain streaming success logging tasks until they finish (#52067) 2026-11-16 11:21:05 -08:00