TEST-INFRA: [flaky-tests] Replace time.sleep() with time mocking in resource_registry tests #3713

Open
opened 2026-04-05 22:16:13 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: test/resource-registry-time-mocking
  • Commit Message: test(resource_registry): replace time.sleep() with time mocking for timestamp tests
  • Milestone: Backlog
  • Parent Epic: #1678

Summary

The Behave tests for the Resource model in features/steps/resource_registry_model_steps.py use time.sleep(0.01) to ensure that the updated_at timestamp is different when testing the with_updated_at() method. While this is a common practice, it can lead to flaky tests, especially when running on heavily loaded systems.

Background

Tests that rely on fixed-time waits are often unreliable because the timing of operations can vary depending on the system load and other factors. A better approach is to mock the time.time() function to control the timestamps directly. This will make the tests more robust and less prone to flakiness. Removing time.sleep() calls also directly reduces CI wall-clock time, aligning with the CI Execution Time Optimization epic (#1678).

Subtasks

  • Identify all instances of time.sleep() in features/steps/resource_registry_model_steps.py.
  • Add a time-mocking helper to features/mocks/ (per project convention — all mocks must live in features/mocks/).
  • Replace the time.sleep() calls with the mock of time.time() that allows for direct control of the timestamps.
  • Ensure that all nox stages pass after the changes.

Definition of Done

  • All time.sleep() calls in features/steps/resource_registry_model_steps.py have been replaced with a time mocking mechanism placed in features/mocks/.
  • The tests in features/steps/resource_registry_model_steps.py are still passing (nox -e unit_tests).
  • The tests are more robust and less prone to flakiness.
  • All nox stages pass
  • Coverage >= 97%

Duplicate Check

  • Searched for issues with keywords: flaky, time.sleep, resource_registry
  • 0 results found.
  • This issue is not a duplicate.

Backlog note: This issue was discovered during autonomous operation
on milestone v3.7.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Test Infrastructure | Agent: ca-new-issue-creator

## Metadata - **Branch**: `test/resource-registry-time-mocking` - **Commit Message**: `test(resource_registry): replace time.sleep() with time mocking for timestamp tests` - **Milestone**: Backlog - **Parent Epic**: #1678 ## Summary The Behave tests for the `Resource` model in `features/steps/resource_registry_model_steps.py` use `time.sleep(0.01)` to ensure that the `updated_at` timestamp is different when testing the `with_updated_at()` method. While this is a common practice, it can lead to flaky tests, especially when running on heavily loaded systems. ## Background Tests that rely on fixed-time waits are often unreliable because the timing of operations can vary depending on the system load and other factors. A better approach is to mock the `time.time()` function to control the timestamps directly. This will make the tests more robust and less prone to flakiness. Removing `time.sleep()` calls also directly reduces CI wall-clock time, aligning with the CI Execution Time Optimization epic (#1678). ## Subtasks - [ ] Identify all instances of `time.sleep()` in `features/steps/resource_registry_model_steps.py`. - [ ] Add a time-mocking helper to `features/mocks/` (per project convention — all mocks must live in `features/mocks/`). - [ ] Replace the `time.sleep()` calls with the mock of `time.time()` that allows for direct control of the timestamps. - [ ] Ensure that all nox stages pass after the changes. ## Definition of Done - [ ] All `time.sleep()` calls in `features/steps/resource_registry_model_steps.py` have been replaced with a time mocking mechanism placed in `features/mocks/`. - [ ] The tests in `features/steps/resource_registry_model_steps.py` are still passing (`nox -e unit_tests`). - [ ] The tests are more robust and less prone to flakiness. - [ ] All nox stages pass - [ ] Coverage >= 97% ### Duplicate Check - Searched for issues with keywords: `flaky`, `time.sleep`, `resource_registry` - 0 results found. - This issue is not a duplicate. > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.7.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Test Infrastructure | Agent: ca-new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#3713
No description provided.