mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix(test): add spend data polling with retries for e2e pass-through tests
- test_vertex_with_spend.test.js: Replace 15s fixed wait with polling loop (up to 6 attempts, 10s apart) for spend data to appear in DB - Increase test timeout from 25s to 90s to accommodate polling - base_anthropic_messages_tool_search_test.py: Add flaky(retries=3) for streaming test that depends on live Anthropic API Co-authored-by: Ishaan Jaff <ishaan-jaff@users.noreply.github.com>
This commit is contained in:
parent
e9424bf3ac
commit
c376b8be58
2 changed files with 27 additions and 30 deletions
|
|
@ -100,21 +100,19 @@ describe('Vertex AI Tests', () => {
|
|||
const callId = lastCallId;
|
||||
console.log("Captured Call ID:", callId);
|
||||
|
||||
// Wait for spend to be logged
|
||||
await new Promise(resolve => setTimeout(resolve, 15000));
|
||||
// Poll for spend data with retries (DB writes can be slow in CI)
|
||||
let spendData = null;
|
||||
for (let attempt = 0; attempt < 6; attempt++) {
|
||||
await new Promise(resolve => setTimeout(resolve, 10000));
|
||||
const spendResponse = await fetch(
|
||||
`http://127.0.0.1:4000/spend/logs?request_id=${callId}`,
|
||||
{ headers: { 'Authorization': 'Bearer sk-1234' } }
|
||||
);
|
||||
spendData = await spendResponse.json();
|
||||
console.log(`spendData (attempt ${attempt + 1}):`, spendData);
|
||||
if (spendData && spendData.length > 0 && spendData[0] && spendData[0].request_id) break;
|
||||
}
|
||||
|
||||
// Check spend logs
|
||||
const spendResponse = await fetch(
|
||||
`http://127.0.0.1:4000/spend/logs?request_id=${callId}`,
|
||||
{
|
||||
headers: {
|
||||
'Authorization': 'Bearer sk-1234'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const spendData = await spendResponse.json();
|
||||
console.log("spendData", spendData)
|
||||
expect(spendData).toBeDefined();
|
||||
expect(spendData[0].request_id).toBe(callId);
|
||||
expect(spendData[0].call_type).toBe('pass_through_endpoint');
|
||||
|
|
@ -123,7 +121,7 @@ describe('Vertex AI Tests', () => {
|
|||
expect(spendData[0].model).toContain('gemini');
|
||||
expect(spendData[0].spend).toBeGreaterThan(0);
|
||||
expect(spendData[0].custom_llm_provider).toBe('vertex_ai');
|
||||
}, 25000);
|
||||
}, 90000);
|
||||
|
||||
test('should successfully generate streaming content with tags', async () => {
|
||||
const vertexAI = new VertexAI({
|
||||
|
|
@ -170,21 +168,19 @@ describe('Vertex AI Tests', () => {
|
|||
const callId = lastCallId;
|
||||
console.log("Captured Call ID:", callId);
|
||||
|
||||
// Wait for spend to be logged
|
||||
await new Promise(resolve => setTimeout(resolve, 15000));
|
||||
// Poll for spend data with retries (DB writes can be slow in CI)
|
||||
let spendData = null;
|
||||
for (let attempt = 0; attempt < 6; attempt++) {
|
||||
await new Promise(resolve => setTimeout(resolve, 10000));
|
||||
const spendResponse = await fetch(
|
||||
`http://127.0.0.1:4000/spend/logs?request_id=${callId}`,
|
||||
{ headers: { 'Authorization': 'Bearer sk-1234' } }
|
||||
);
|
||||
spendData = await spendResponse.json();
|
||||
console.log(`spendData (attempt ${attempt + 1}):`, spendData);
|
||||
if (spendData && spendData.length > 0 && spendData[0] && spendData[0].request_id) break;
|
||||
}
|
||||
|
||||
// Check spend logs
|
||||
const spendResponse = await fetch(
|
||||
`http://127.0.0.1:4000/spend/logs?request_id=${callId}`,
|
||||
{
|
||||
headers: {
|
||||
'Authorization': 'Bearer sk-1234'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const spendData = await spendResponse.json();
|
||||
console.log("spendData", spendData)
|
||||
expect(spendData).toBeDefined();
|
||||
expect(spendData[0].request_id).toBe(callId);
|
||||
expect(spendData[0].call_type).toBe('pass_through_endpoint');
|
||||
|
|
@ -193,5 +189,5 @@ describe('Vertex AI Tests', () => {
|
|||
expect(spendData[0].model).toContain('gemini');
|
||||
expect(spendData[0].spend).toBeGreaterThan(0);
|
||||
expect(spendData[0].custom_llm_provider).toBe('vertex_ai');
|
||||
}, 25000);
|
||||
}, 90000);
|
||||
});
|
||||
|
|
@ -206,6 +206,7 @@ class BaseAnthropicMessagesToolSearchTest(ABC):
|
|||
assert len(tool_uses) > 0, "Expected tool_use blocks when stop_reason is tool_use"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.flaky(retries=3, delay=5)
|
||||
async def test_tool_search_streaming(self):
|
||||
"""
|
||||
E2E test: Tool search should work with streaming responses.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue