litellm/tests/unit/proxy/utils
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
..
helpers fix(responses): run the guardrails a Responses WebSocket frame selects (#48725) 2026-10-30 14:12:51 -07:00
prisma_and_spend fix(proxy): retain unwritten rollups after database disconnects (#51706) 2026-11-13 13:36:12 -08:00
proxy_logging fix(logging): retain streaming success logging tasks until they finish (#52067) 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