Skip to content

Studio: stop sleeping in the API-key expiry cache test - #10260

Closed
Souravrajvi0 wants to merge 1 commit into
unslothai:mainfrom
Souravrajvi0:feat/api-key-expiry-test-flake-fef2
Closed

Souravrajvi0 wants to merge 1 commit into
unslothai:mainfrom
Souravrajvi0:feat/api-key-expiry-test-flake-fef2

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Summary

Part of #10147 (the flaky-test follow-up from #10076).

tests/test_api_key_expiry.py::test_cache_does_not_bypass_expiry minted a key that expired in 600 ms, asserted it was still valid, then slept 0.8 s. Under parallel CI that window can already have elapsed before the first assertion, which is the flake recorded on the issue.

This drives storage.datetime.now instead of wall-clock sleep. The hash cache is still warmed on the first call and the second call still re-checks expires_at.

Changes

  • Replace the 600 ms TTL + time.sleep with a frozen clock around the two validate_api_key calls

Test plan

  • python -m pytest tests/test_api_key_expiry.py -q --tb=short (15 passed)

test_cache_does_not_bypass_expiry minted a key that expired in 600 ms
and then slept. Under parallel CI that window could elapse before the
first assertion, which is the flake recorded on unslothai#10147. Drive
storage.datetime.now instead so the cached hash still re-checks
expires_at without depending on wall-clock timing.
@danielhanchen

Copy link
Copy Markdown
Member

main now removes that sleep in studio/backend/tests/test_api_key_expiry.py by expiring the key row after the cache is warmed, so I do not think this is needed any more. Sorry for the slow review, and thanks for putting it together.

@danielhanchen danielhanchen self-assigned this Oct 1, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for the PR! Closing this as superseded by #10952, which is now on main. That change removes the 600 ms TTL and the sleep from test_cache_does_not_bypass_expiry by warming the cache on a key valid for a day, then expiring the key in its database row and checking that the cached lookup still rejects it. It also asserts the second call takes the cache path. That covers the flake from #10147 without patching storage.datetime, so there is nothing left for this PR to add, and it now conflicts with main on the same lines. Thanks again for tracking this down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants