Skip to content

Replace timer-based TTL expiration tests with fake clock #9112

@waveywaves

Description

@waveywaves

Context

In PR #9051, we implemented a shared resolver cache with TTL-based expiration. The current unit tests for TTL expiration use time.Sleep() to wait for cache entries to expire, which makes tests slower and potentially flaky.

Task

Replace the timer-based approach in TestCacheTTLExpiration with a fake clock implementation.

Current Implementation

The test currently uses:

time.Sleep(ttl + (100 * time.Millisecond))

Proposed Solution

  • Use the existing fakeClock type that's already in the cache package
  • Inject the fake clock into the cache instance
  • Advance the clock programmatically instead of sleeping
  • This will make tests faster, more deterministic, and less flaky

Files to Modify

  • pkg/remoteresolution/resolver/framework/cache/cache_test.go (TestCacheTTLExpiration)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions