Files
local-deep-research/tests/database
LearningCircuit 057a4ceab8 test(database): migrate 2 credential_store TTL tests to freezegun (#4235)
Two tests in test_credential_store_behavior.py used real time.sleep(1.5)
to wait for TTL expiration:

  test_credentials_expire_after_ttl     (TTL=1, sleep 1.5)
  test_expired_entries_cleaned_on_store (TTL=1, sleep 1.5)

The SUT (credential_store_base.py) compares time.time() to expires_at:

  src/local_deep_research/database/credential_store_base.py:47
      \"expires_at\": time.time() + self.ttl
  src/local_deep_research/database/credential_store_base.py:73
      if time.time() > entry[\"expires_at\"]:

freezegun fully mocks time.time(), so swapping time.sleep(1.5) for
frozen.tick(1.5) gives identical behavior without the wall-clock wait.

NOT migrated:

  test_credential_store_extended.py:172 -
  test_expired_entry_returns_none_after_ttl

  Its docstring explicitly says \"This test deliberately uses a real
  time.sleep instead of freeze_time so that the rest of the freezegun-
  based suite is validated against the actual time.time() clock at least
  once. Don't migrate this one without keeping another integration
  anchor.\" — respecting that intent.

Time saved per CI run: ~3s (was 1.5 + 1.5 = 3s real wait, now near-zero).
Eliminates wall-clock-jitter flakes around the int(time.time())
truncation that the original tests already worked around with 1.5s buffer.

Verified locally:
  pytest tests/database/test_credential_store_behavior.py
  => 30 passed in 12.45s
  test_credentials_expire_after_ttl:    6.37s (was longer)
  test_expired_entries_cleaned_on_store: 0.52s (was ~1.5s sleep)

Twenty-ninth PR in the systematic test-quality review series.
2026-05-24 09:33:03 +02:00
..