Skip to content

Tests: replace fixed sleeps with a polling wait_for helper #512

Closed

Description

@antosubash

Tier 3: test reliability

Problem

Tests contain about 27 non-zero asyncio.sleep / time.sleep calls, mostly in background_tasks. Examples:

  • test_bg_invalidation_redis.py:148,197: sleep(0.3)
  • test_bg_outbox_retry_policy.py:135: sleep(0.6)
  • test_bg_invalidation_degraded.py:114: sleep(0.2)
  • test_events.py:110
  • test_file_storage_thumbnail_hardening.py:186

Some are deliberate "block forever" stubs (30 s, 5 s), and those are fine. The fixed 0.2-0.6 s waits are bets on timing. They flake on a loaded CI runner and make the suite slower than it needs to be on a fast one.

Fix

  • Add wait_for(predicate, timeout=2.0, interval=0.01) (async and sync versions) to simple_module_test.
  • Replace each fixed wait that stands in for "until X happened".
  • Optionally add a lint script that flags new sleep(<float>) in tests/ without an # intentional-sleep: marker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions