Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix flaky vertex pass-through spend test by polling instead of fixed sleep

yuneng-jiang0b9a24202e59
diff --git a/tests/pass_through_tests/test_vertex_ai.py b/tests/pass_through_tests/test_vertex_ai.py
index b3a99bc5533..2f5ec8eaa3e 100644
--- a/tests/pass_through_tests/test_vertex_ai.py
+++ b/tests/pass_through_tests/test_vertex_ai.py
@@ -109,17 +109,25 @@ async def test_basic_vertex_ai_pass_through_with_spendlog():
print("response", response)
- await asyncio.sleep(40)
- spend_after = await call_spend_logs_endpoint()
- print("spend_after", spend_after)
+ # Poll for spend update instead of fixed sleep - spend logging is async/batched
+ max_wait = 120 # total seconds to wait
+ poll_interval = 10 # seconds between checks
+ elapsed = 0
+ spend_after = spend_before
+ while elapsed < max_wait:
+ await asyncio.sleep(poll_interval)
+ elapsed += poll_interval
+ spend_after = await call_spend_logs_endpoint() or 0.0
+ print(f"spend_after (elapsed={elapsed}s)", spend_after)
+ if spend_after > spend_before:
+ break
+
assert (
spend_after > spend_before
- ), "Spend should be greater than before. spend_before: {}, spend_after: {}".format(
- spend_before, spend_after
+ ), "Spend should be greater than before after {}s. spend_before: {}, spend_after: {}".format(
+ elapsed, spend_before, spend_after
)
- pass
-
@pytest.mark.asyncio()
@pytest.mark.skip(reason="skip flaky test - vertex pass through streaming is flaky")