Skip to content

Stop the Attest Timing Tests Recording Subprocess Polling Sleeps #2934

Closed

Description

@ptr727

Defect

tests/test_pr_review.py TestAttest.lagging records sleeps with mock.patch.object(pr_review.time, "sleep", side_effect=self.slept.append). pr_review.time is the process-wide time module, so the patch also catches every other time.sleep call made while attest runs. attest runs the stubbed local_review.py through subprocess, and a POSIX Popen wait with a timeout polls in a loop that sleeps in growing steps from 0.0005 seconds. When the stub process is slow to exit, those polling sleeps land in self.slept beside the ATTEST_HEAD_DELAYS ones.

Two assertions fail intermittently as a result, each passing on a rerun:

  • test_a_head_that_catches_up_within_the_bound_is_attested: assertEqual(2, len(self.slept)) sees 3.
  • test_a_head_that_never_catches_up_is_refused_after_the_bound: assertLessEqual(sum(self.slept), 60) sees 60.001, since ATTEST_HEAD_DELAYS sums to exactly 60.

Both appeared during one round of parallel lanes on a loaded host, in separate full-suite runs.

Possible direction

Record only the sleeps await_registered_head makes. Either have pr_review call a module-level _sleep = time.sleep alias that the test patches instead of the shared module attribute, or filter the recorded calls to the values in ATTEST_HEAD_DELAYS. The first keeps the assertions exact. Check the file's other pr_review.time.sleep patches for the same exposure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    script

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions