Skip to content

Conversation

@Pouyanpi
Copy link
Collaborator

Summary

Fixes a flaky test in test_cache_lfu.py that was intermittently failing on CI due to timing dependencies.

Problem

The test relied on time.sleep(0.05) with an assumption that 10 iterations would take < 1.0 seconds. On CI, execution overhead from cache operations and system load caused cumulative delays that would occasionally push total time over 1.0 seconds, triggering unexpected stats logging and causing the test to fail with AssertionError: 1 != 0.

Solution

Mock time.time() with controlled values that advance exactly 0.05 seconds per iteration, removing all timing dependencies.

Changes

  • Replaced real time.sleep() calls with mocked time.time() in test_stats_logging_interval_timing
  • Eliminates execution overhead and scheduling delays that caused test flakiness
  • Test now runs deterministically across all environments

Benefits

  • Eliminates flakiness on CI
  • Faster test execution (~0.02s vs ~1.16s, 58x speedup)
  • Deterministic behavior across all environments

Test plan

  • Test passes locally (5/5 runs)
  • Pre-commit hooks pass
  • CI validates fix resolves flakiness

Replace real time.sleep() calls with mocked time.time() to eliminate
timing dependencies that caused intermittent CI failures. The test
would occasionally fail when execution overhead pushed total elapsed
time over the 1.0 second threshold, triggering unexpected stats logging.

Mocking time.time() ensures deterministic behavior across all
environments
and reduces test execution time from ~1.16s to ~0.02s.
@Pouyanpi Pouyanpi changed the title Fix/flaky cache stats logging test test: fix flaky stats logging interval timing test" Oct 20, 2025
@Pouyanpi Pouyanpi changed the title test: fix flaky stats logging interval timing test" test: fix flaky stats logging interval timing test Oct 20, 2025
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@tgasser-nv tgasser-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better, thanks for fixing this

@Pouyanpi Pouyanpi requested review from hazai and phtran8 October 21, 2025 07:47
@Pouyanpi Pouyanpi merged commit 861ec38 into develop Oct 21, 2025
32 checks passed
@Pouyanpi Pouyanpi deleted the fix/flaky-cache-stats-logging-test branch October 21, 2025 07:47
Pouyanpi added a commit that referenced this pull request Oct 28, 2025
Replace real time.sleep() calls with mocked time.time() to eliminate
timing dependencies that caused intermittent CI failures. The test
would occasionally fail when execution overhead pushed total elapsed
time over the 1.0 second threshold, triggering unexpected stats logging.

Mocking time.time() ensures deterministic behavior across all
environments
and reduces test execution time from ~1.16s to ~0.02s.
tgasser-nv pushed a commit that referenced this pull request Oct 28, 2025
Replace real time.sleep() calls with mocked time.time() to eliminate
timing dependencies that caused intermittent CI failures. The test
would occasionally fail when execution overhead pushed total elapsed
time over the 1.0 second threshold, triggering unexpected stats logging.

Mocking time.time() ensures deterministic behavior across all
environments
and reduces test execution time from ~1.16s to ~0.02s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants