mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
test(caching): pin which max-age key wins when a request sends both
The test now asserts that s-max-age decides on both the sync and the async cache read, so swapping the key order on both reads fails it
This commit is contained in:
parent
c5fbd1c3c3
commit
dfc92ba4cd
1 changed files with 10 additions and 5 deletions
|
|
@ -1457,11 +1457,15 @@ def test_sync_completion_with_zero_s_maxage_skips_the_cached_response(
|
|||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"cache_controls",
|
||||
[{"s-maxage": 0, "s-max-age": 60}, {"s-maxage": 60, "s-max-age": 0}, {"s-maxage": None, "s-max-age": 0}],
|
||||
("cache_controls", "serves_cached"),
|
||||
[
|
||||
({"s-maxage": 0, "s-max-age": 60}, True),
|
||||
({"s-maxage": 60, "s-max-age": 0}, False),
|
||||
({"s-maxage": None, "s-max-age": 0}, False),
|
||||
],
|
||||
)
|
||||
async def test_sync_and_async_completion_agree_on_the_cache_when_both_max_age_keys_are_sent(
|
||||
monkeypatch: pytest.MonkeyPatch, cache_controls: dict[str, int | None]
|
||||
async def test_sync_and_async_completion_follow_s_max_age_when_both_max_age_keys_are_sent(
|
||||
monkeypatch: pytest.MonkeyPatch, cache_controls: dict[str, int | None], serves_cached: bool
|
||||
) -> None:
|
||||
monkeypatch.setattr(litellm, "cache", Cache(type=LiteLLMCacheType.LOCAL))
|
||||
sync_messages: Final = [{"role": "user", "content": f"sync both max-age keys {uuid.uuid4().hex}"}]
|
||||
|
|
@ -1476,7 +1480,8 @@ async def test_sync_and_async_completion_agree_on_the_cache_when_both_max_age_ke
|
|||
model="gpt-4o-mini", messages=async_messages, cache=cache_controls, mock_response="second"
|
||||
)
|
||||
|
||||
assert (sync_second.id == sync_first.id) == (async_second.id == async_first.id)
|
||||
assert (sync_second.id == sync_first.id) is serves_cached
|
||||
assert (async_second.id == async_first.id) is serves_cached
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue