mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
test(response_metadata): make the detailed-timing receive-anchor test timezone independent (#42429)
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
This commit is contained in:
parent
88a4cbdd7b
commit
4b65ef6d64
1 changed files with 14 additions and 2 deletions
|
|
@ -7,6 +7,8 @@ through _hidden_params to the x-litellm-callback-duration-ms response header.
|
|||
|
||||
import asyncio
|
||||
import datetime
|
||||
import time
|
||||
from collections.abc import Iterator
|
||||
from typing import Final
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
|
@ -427,6 +429,15 @@ class TestCallbackDurationInCustomHeaders:
|
|||
assert "x-litellm-callback-duration-ms" not in headers
|
||||
|
||||
|
||||
@pytest.fixture(params=["UTC", "Asia/Kolkata", "America/Los_Angeles"])
|
||||
def process_timezone(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) -> Iterator[str]:
|
||||
monkeypatch.setenv("TZ", request.param)
|
||||
time.tzset()
|
||||
yield request.param
|
||||
monkeypatch.undo()
|
||||
time.tzset()
|
||||
|
||||
|
||||
class TestDetailedTiming:
|
||||
"""Tests for detailed per-phase timing headers behind LITELLM_DETAILED_TIMING."""
|
||||
|
||||
|
|
@ -472,13 +483,14 @@ class TestDetailedTiming:
|
|||
assert hidden.get("timing_pre_processing_ms") == 20.0
|
||||
assert hidden.get("timing_post_processing_ms") == 10.0 # 530 - 20 - 500
|
||||
|
||||
def test_detailed_timing_pre_processing_uses_receive_anchor(self, monkeypatch):
|
||||
@pytest.mark.skipif(not hasattr(time, "tzset"), reason="switching the process timezone needs time.tzset()")
|
||||
def test_detailed_timing_pre_processing_uses_receive_anchor(self, monkeypatch, process_timezone: str):
|
||||
monkeypatch.setattr(response_metadata_mod, "LITELLM_DETAILED_TIMING", True)
|
||||
|
||||
result = ModelResponse()
|
||||
received_at = datetime.datetime(2025, 1, 1, tzinfo=datetime.timezone.utc)
|
||||
start = received_at + datetime.timedelta(milliseconds=200)
|
||||
api_call_start = start.replace(tzinfo=None)
|
||||
api_call_start = start.astimezone().replace(tzinfo=None)
|
||||
end = start + datetime.timedelta(milliseconds=530)
|
||||
logging_obj = self._make_logging_obj(
|
||||
llm_api_duration_ms=500.0,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue