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:
mateo-berri 2026-11-10 10:13:02 -08:00
parent c5fbd1c3c3
commit dfc92ba4cd

View file

@ -1457,11 +1457,15 @@ def test_sync_completion_with_zero_s_maxage_skips_the_cached_response(
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.parametrize( @pytest.mark.parametrize(
"cache_controls", ("cache_controls", "serves_cached"),
[{"s-maxage": 0, "s-max-age": 60}, {"s-maxage": 60, "s-max-age": 0}, {"s-maxage": None, "s-max-age": 0}], [
({"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( 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] monkeypatch: pytest.MonkeyPatch, cache_controls: dict[str, int | None], serves_cached: bool
) -> None: ) -> None:
monkeypatch.setattr(litellm, "cache", Cache(type=LiteLLMCacheType.LOCAL)) monkeypatch.setattr(litellm, "cache", Cache(type=LiteLLMCacheType.LOCAL))
sync_messages: Final = [{"role": "user", "content": f"sync both max-age keys {uuid.uuid4().hex}"}] 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" 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 @pytest.mark.asyncio