Skip to content

test: wait on conditions, and fail a new test sleep or timer - #1036

Merged
napetrov merged 12 commits into
intel:mainfrom
antonwolfy:test/wait-not-sleep
Nov 22, 2026
Merged

napetrov merged 12 commits into
intel:mainfrom
antonwolfy:test/wait-not-sleep

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tests that wait on a fixed time.sleep or threading.Timer for another thread or process to reach a state fail on a slow or busy runner: the Ctrl-C lifecycle test was fixed four times, the SIGTERM reach test twice, and tests/test_run_wide_stop.py still races a 0.2 s timer. On main there is no shared helper to wait on a condition (each file writes its own polling loop), and nothing stops the next sleep: running the new check over main's tests/ with an empty baseline exits 1 with 15 files above their (missing) entry.

The issue counts 73 time.sleep( and 2 threading.Timer( by grep. The AST count is lower, 23 calls in 15 files on main (21 time.sleep and 2 threading.Timer), because most grep hits are a child's source or shell command inside a string ("import time; time.sleep(60)"), which is not a call. This PR's pid_state.py loses its one sleep, and main has since removed the sleep in tests/test_run_wide_stop.py, so the baseline holds 21 calls in 13 files (20 time.sleep, 1 threading.Timer).

The fix is the helper plus the check. Moving the existing sleeps onto the helper is out of scope: the baseline holds them and only shrinks. The elapsed-time assertion is left to review (REVIEW.md).

Closes #1034

Changes

  • tests/waiting.py (new): poll_until(predicate, timeout, interval=0.02) -> bool (False at the deadline, never raises; it sleeps at most the time left and checks the clock after each sleep, so a condition that becomes true only after the deadline is not accepted, also when a sleep overshoots it or a later call is slow; the first call is made whatever the timeout), wait_until(predicate, timeout, *, what, interval=0.02) (returns the first truthy value, otherwise pytest.fail("gave up after <timeout> s waiting for <what>"); what is required) and wait_for_event(event, timeout, *, what).
  • tests/pid_state.py: wait_until_gone is the pid-exit wait the issue asks for next to the event helper; it stays beside the other pid helpers and is rebuilt on poll_until, with the same signature and result (the pids still running after grace_s, no failure). Its time.sleep is gone. tests/test_pid_state.py patches the time module where it patched pid_state.time, which pid_state no longer imports; its assertions are unchanged.
  • scripts/check_test_timing.py and scripts/test_timing_baseline.json (new, stdlib only): counts, per file under tests/, the calls the file's imports resolve to time.sleep or threading.Timer (import time, import time as t, from time import sleep [as nap], from time import *, and the same for Timer). Only imports are followed: nap = time.sleep then nap(1) is not counted. A name means what the innermost scope that binds it says (function, lambda, comprehension, module; a class body is not visible from its methods), so import threading as t in one test does not hide import time as t; t.sleep() in another, and a parameter, assignment or def of the same name shadows an import. In the scope a call stands in, the last binding before the call counts, so import time, time.sleep(1), time = None counts the sleep; a comprehension's targets stay in it ([time for time in ()] does not rebind time), its first iterable is read outside it and a := binds outside, taking effect after that first iterable of each comprehension around it (which Python runs first) but not hidden from the rest of the element, while a := inside a lambda's body in the comprehension stays local to the lambda (its defaults bind outside); a := in a def or lambda default, a decorator or a class base binds in the scope around it too. A name declared global or nonlocal in a function is not local to it, so rebinding it does not hide an import; an annotation with no value (time: object) binds nothing in a module or class body; a for target binds after its iterable; a class body reads outer names by position, as it runs where it stands. The element of a list, set or dict comprehension runs after its iterables and filters, so its := is not in effect for a call in a filter or a later iterable; a generator expression runs only its first iterable where it stands, so a := in the rest of it binds nothing around it. A def's parameter and return annotations are read as calls where the def stands (they run there before Python 3.14), unless the file has from __future__ import annotations; a := in one of those annotations rebinds its name in the scope around the def (also unless postponed), so a later call of the old import is not counted. The annotation of x: T is not read as a call when annotations are postponed or the statement is in a function body (where Python never evaluates it); its value is, and a module or class level annotation otherwise is; a := in an annotation that is not evaluated rebinds nothing, with or without a value. A := in the iterable or a filter of a list, set or dict comprehension (also a nested one) runs before the element, so it is in effect for the element even though the element stands first in the text, and not for a call that runs before it. A string is not a call. Where branches meet (if/else, try/except, match cases), a name counts when any branch may have bound it to a sleep or timer, so time.sleep as wait on Windows and my_helpers.wait elsewhere is counted; a later binding on every path to the call, or a binding in an arm the call is not in, still hides an earlier one. A baseline that is not {"files": {<file>: <count>}} with integer counts (1.9 and "2" are refused; a missing files key is refused, an explicit {"files": {}} is accepted), and a test file that cannot be read or parsed, exit 1 with a message naming it. A --tests-root that is not a directory exits 2 before anything is scanned or written. tests/waiting.py is not counted. A count above its entry, a file with no entry, or a count below its entry fails (exit 1), as in scripts/check_growth.py. --update lowers or drops entries, refuses (exit 1, baseline untouched) while any file is above its entry, and writes a first baseline when the file is missing (every file at its current count; the --update help says so). A call whose first or last line ends with # timing-ok: <reason> is not counted; a # timing-ok with no reason fails with its file and line.
  • .github/workflows/ci.yml: a Test timing ratchet step in the static job after Duplicate code ratchet (make ci-local lists it from the workflow).
  • tests/test_check_test_timing.py and tests/test_waiting.py (new), plus a test that runs the check on the repo's own tree and baseline.
  • AGENTS.md and REVIEW.md: a bullet each, naming the helper and the check.
  • No changelog fragment: no package code under dokimi/dokimi/ changes.

Risk

A test-only change. Anyone who adds a time.sleep or threading.Timer to tests/ now fails the static job unless the line says # timing-ok: <reason>; anyone who removes one must run python scripts/check_test_timing.py --update, because a count below its entry fails too. The open PR that removes the threading.Timer in tests/test_run_wide_stop.py (#987) lowers a count: whichever of the two merges second runs --update. #958 changes the run: line of guidance self-scan (L0) two lines below the new step, which sits between Duplicate code ratchet and that step and leaves its lines untouched: git merge-tree of this branch with #958's head merges ci.yml cleanly.

Testing

On a Linux review host, at 35f55acc (on main 2701798):

  • make ci-local: 37 passed, 0 failed, 14 skipped (steps that need other Pythons, micromamba, semgrep, a deploy or a PR event). 24310 tests passed, 0 failed, 19 skipped. The Test timing ratchet step at this head printed: test timing ratchet ok: 21 sleep/Timer call(s) in 13 file(s): 1 threading.Timer, 20 time.sleep.
  • On a copy of main's tree with only this branch's tests/waiting.py, scripts/check_test_timing.py and scripts/test_timing_baseline.json added (main's tests/pid_state.py keeps its time.sleep):
    • tests/test_check_test_timing.py: 1 failed, 26 passed. test_the_repo_tree_holds_its_own_baseline fails on tests/pid_state.py: 1 sleep/Timer call(s), above no baseline entry, which is the check refusing a sleep its baseline does not hold.
    • tests/test_waiting.py: 5 passed. The helper is new, so there is no old behaviour for it to fail on.
  • Mutants, each failing the test named: dropping the from time import sleep resolution fails the two from time import cases of test_each_way_to_import_a_sleep_or_timer_is_counted; counting an empty # timing-ok: reason as waived fails the three cases of test_a_waiver_without_a_reason_fails_naming_its_line; skipping the under-baseline failure fails test_a_count_under_its_entry_fails_until_update_lowers_it; letting --update run with a file above its entry fails test_update_refuses_while_a_file_is_over_its_entry_and_leaves_the_baseline_alone; not exempting waiting.py fails test_waiting_py_is_not_counted; not resolving threading.Timer fails its four import cases; wait_until returning before the predicate holds fails test_wait_until_returns_the_value_of_the_call_that_turned_truthy; dropping what from wait_until's and from wait_for_event's message fails test_wait_until_fails_at_the_deadline_naming_what_it_waited_for_and_for_how_long and test_wait_for_event_fails_naming_what_it_waited_for_when_the_event_is_never_set; poll_until raising at the deadline fails test_poll_until_returns_false_at_the_deadline_and_true_once_the_predicate_holds.
  • Scoping, root check and deadline, each failing on the code it pins: merging every scope's bindings into the module's fails three cases of test_a_name_means_what_the_innermost_scope_that_binds_it_says; skipping the is_dir check fails both cases of test_a_tests_root_that_is_not_a_directory_exits_2_and_leaves_the_baseline_alone; sleeping a full interval in poll_until fails test_poll_until_never_sleeps_past_the_deadline_so_a_late_condition_is_not_accepted (a fake clock, interval 1 s, timeout 0.01 s, condition true from 0.5 s: it returns True instead of False). All three tests also fail on the previous head's code.
  • Binding order, comprehensions, star imports, unreadable inputs and oversleep, each failing on the code it pins (and all 14 new cases failing on the previous head's code): reading a name by its final binding instead of the last one before the call fails test_a_name_means_what_the_innermost_scope_that_binds_it_says; binding a comprehension's targets in the enclosing scope, or not reading its first iterable outside, fails the same test; a from time import * that binds nothing fails test_each_way_to_import_a_sleep_or_timer_is_counted; accepting {"files": null} or not catching a baseline error fails test_a_baseline_that_is_not_one_fails_naming_it; not catching a non-UTF-8 file, a dangling symlink or a syntax error fails test_a_test_file_that_cannot_be_read_fails_naming_it_instead_of_raising; ignoring the clock after a sleep fails test_poll_until_does_not_accept_a_condition_reached_while_a_sleep_overshot_the_deadline (a fake clock whose sleep advances 0.5 s, timeout 0.01 s: it returned True, now False).
  • Walruses, each failing on the code it pins: letting the walrus search enter a lambda fails the (lambda: (time := None)) case of test_a_name_means_what_the_innermost_scope_that_binds_it_says, and binding a comprehension walrus at its own position instead of after the first iterable fails the [(time := None) for _ in (time.sleep(1),)] case of the same test.
  • Scope and execution order, each failing on the code it pins: dropping the global/nonlocal handling fails the global time and nonlocal time cases of test_a_name_means_what_the_innermost_scope_that_binds_it_says; binding a valueless annotation fails its module and class cases; binding a for target at its own position fails for time in (time.sleep(1),); not reading outer names by position from a class body fails class T: time.sleep(1) followed by time = None; skipping lambda defaults in the walrus search fails (lambda x=(time := None): x); ignoring the spans that hide a walrus fails the element-walrus and nested-comprehension cases; keeping only the innermost comprehension's span fails [[(time := None) for x in (0,)] for _ in (time.sleep(1),)]. Accepting any truthy later poll_until call regardless of the clock fails test_poll_until_does_not_accept_a_value_a_slow_later_call_returns_after_the_deadline (a fake clock whose second predicate call advances 0.1 s, timeout 0.01 s: it returned True, now False).
  • Walruses in defaults and baseline counts, each failing on the code it pins: not reading a def's defaults, decorators and class bases for a := fails the def f(x=(time := None)), decorator and class-base cases of test_a_name_means_what_the_innermost_scope_that_binds_it_says; not reading a lambda outside a comprehension for one fails f = lambda x=(time := None): x; accepting a float or string count through int() fails both new cases of test_a_baseline_that_is_not_one_fails_naming_it.
  • Generators, filters and annotations, each failing on the code it pins (tests/test_check_test_timing.py has 91 cases, 11 of them new): letting a generator expression's body bind its := fails ((time := None) for _ in (0,)) followed by time.sleep(1) (1 failed); not hiding the element's := from the iterables and filters fails the filter, later-iterable and dict-comprehension cases (6 failed); not reading annotations fails the parameter, return and *args/**kwargs cases (3 failed). A from __future__ import annotations file counts none of them.
  • Annotation bindings and unevaluated annotations (tests/test_check_test_timing.py has 99 cases, 8 of them new): not binding a := from a parameter or return annotation fails both rebinding cases (def test_a(x: (sleep := ...)) and -> (sleep := ...), 2 failed); reading the annotation of x: T regardless of postponement or function scope fails the postponed module case and the function-local case (2 failed).
  • Local annotation walrus and filter bindings (tests/test_check_test_timing.py has 111 cases, 12 of them new): reading the annotation of a local x: (time := None) or x: (time := None) = 0, or of a postponed module one, fails those three cases (3 failed); binding a := of an iterable or filter only after its own text fails the list, set, dict, first-iterable, second-generator and nested cases (8 failed).
  • Branches and the files key (tests/test_check_test_timing.py has 126 cases, 15 of them new): reading files with a default of {} fails the {} and {"wrong_key": {}} cases of test_a_baseline_that_is_not_one_fails_naming_it (2 failed); keeping only the last binding of a name instead of every one that may have run fails 6 cases of test_a_name_bound_differently_in_each_branch_counts_when_any_branch_makes_it_a_sleep; keeping every earlier binding, never hidden by a later one, fails 27 cases across that test and the scoping test.
  • Not run: the matrix legs on Python 3.11, 3.12 and 3.14.

Open questions

None.

Revert

A plain revert removes the helper, the check, its baseline, the CI step and the two doc bullets, and restores wait_until_gone's own loop. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

)

Tests that waited on a fixed time.sleep or threading.Timer for another thread or process failed on a slow runner, and each file wrote its own polling loop.

tests/waiting.py gives poll_until (False at the deadline), wait_until (pytest.fail naming what it waited for) and wait_for_event; pid_state.wait_until_gone is rebuilt on poll_until with the same signature and result.

scripts/check_test_timing.py counts, per file under tests/, the calls that resolve to time.sleep or threading.Timer through the file's imports and fails a count above or below its entry in scripts/test_timing_baseline.json, or a bare `# timing-ok`; --update only lowers entries. It runs in the static job of ci.yml.

AGENTS.md and REVIEW.md name the helper and the check. test_pid_state.py patches the time module instead of pid_state.time, which pid_state no longer imports.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 19, 2026 21:07
@antonwolfy antonwolfy self-assigned this Nov 19, 2026
@exai-bot

exai-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

OpenCodeReview: Commit 35f55ac was not reviewed. This PR has reached its review limit (6 reviews).

CI at `35f55ac`: 9 still running, 3 passing, 1 skipped
Check Status
Build docs (strict) still running
CodeQL (actions) still running
CodeQL (python) still running
Dependency review still running
External catalog smoke test (uxlfoundation/skills) still running
Platforms and Python versions still running
Static checks (ruff, schema, zizmor, licenses, pre-commit, bandit, secrets, changelog, schema com... still running
benchmark still running
mypy still running

To review this commit: re-request review from exai-bot in the Reviewers list.

<details><summary>Last review (1b3e6ad): no findings</summary>

Open threads from the bot: 0

</details>

Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/tests/waiting.py Resolved
@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.91%. Comparing base (2701798) to head (35f55ac).
⚠️ Report is 26 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1036    +/-   ##
========================================
  Coverage   95.91%   95.91%            
========================================
  Files         448      450     +2     
  Lines       59389    59527   +138     
  Branches    10240    10265    +25     
========================================
+ Hits        56963    57098   +135     
- Misses       1506     1507     +1     
- Partials      920      922     +2     

see 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… bad root; poll_until does not sleep past its deadline

Settles three review points on intel#1036.

check_test_timing.py resolved every import of a file in one table, so `import threading as t` in one test hid `import time as t; t.sleep()` in another. A name now means what the innermost scope that binds it says (function, lambda, module; a class body is not visible from its methods), and a parameter, assignment or def of the same name shadows an import.

`--tests-root` that is not a directory now exits 2 before anything is scanned, so `--update` cannot replace the baseline with an empty one.

poll_until slept a full interval even when less time was left, so a condition that became true after the deadline was accepted. It now sleeps at most the remaining time, then makes its last call.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/tests/waiting.py Resolved

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Changes needed: 1 must-fix, 1 nit · reviewed adfc656

Next: @antonwolfy: fix the 1 must-fix finding, answer 3 open threads from exai-bot and settle 3 open questions; then push for a re-review. 1 nit optional.

Blocking

  • Still holds on this head: thread by exai-bot – import time, time.sleep(1) and then time = None scan to zero calls on the head, so the sleep is not counted.
  • Still holds on this head: thread by exai-bot – [time for time in ()] before time.sleep(1) scans to zero calls on the head, so the sleep is not counted.
  • Still holds on this head: thread by exai-bot – A nap that advances the clock by 0.5 s makes poll_until(..., 0.01, interval=1) return True on the head, after the deadline.
  • Open question for @antonwolfy: Issue #1034 asks tests/waiting.py for a pid-exit helper next to the event helper. Move the pid wait into tests/waiting.py, or state in the description that wait_until_gone is that helper.
  • Open question for @antonwolfy: A name bound to time.sleep by assignment (nap = time.sleep, then nap(1)) scans to zero calls, though the docstring counts the calls the imports resolve to. Count the assignment, or state in the docstring that only imports are followed.
  • Open question for @antonwolfy: --update with no baseline file writes the counts of the whole tree, so a new sleep enters the baseline, while the --update help says it never raises an entry. Refuse the first write unless the file is missing on purpose, or change the help text to say the first write sets every count.

Verified on adfc656: ✅ changed tests: 49 passed, fail on main · ✅ full suite with main merged in: 23978 passed · ✅ merges onto main · ✅ 12 broken variants of the changed code: 11 caught by the tests · 1 mutation tried · 9 edge inputs tried

14 checks behind it, each with its evidence
Area What holds How
Changed tests The three changed test files pass on the head, 49 cases, and pin the counting, scoping, root, waiver, poll_until, wait_until, wait_for_event and wait_until_gone behaviour tests on the head
Root check A --tests-root that is missing or is a file exits 2 with the baseline unchanged, with or without --update, as test_a_tests_root_that_is_not_a_directory_exits_2_and_leaves_the_baseline_alone pins tests on the head, edge input (paths)
Waivers A call on a line with # timing-ok: <reason> is not counted, and a bare # timing-ok fails with its line number, as the waiver tests pin tests on the head
New tests on main On main the new check test module fails to import, since check_test_timing is not there, so the tests are new and not vacuous same tests on main
Baseline count The tests tree counts 22 sleep or timer calls in 14 files, 20 time.sleep and 2 threading.Timer, which is the sum of the committed baseline ran it
Full check The full check run on the head merged onto main has 0 failed, 26 passed and 20 skipped full suite, main merged in
Merge The head merges onto main with no conflict merge onto main
Line endings and non-ascii A CRLF file with a non-ASCII comment counts its sleep, and a waiver with a reason on a CRLF line is not counted ran it, edge input (text)
Empty root and dump order An empty tests root measures as no calls, and the baseline dump lists its entries in sorted order ran it, edge input (collections)
Zero and negative timeout poll_until with a timeout of 0 or -1 calls the predicate once and returns False ran it, edge input (numbers)
Baseline shape A baseline with no files key loads as empty, and an extra key is ignored ran it, edge input (structured)
Option without a value --tests-root with no value exits 2 through argparse ran it, edge input (cli)
Relative root A relative --tests-root is read from the working directory and its keys read tests/... ran it, edge input (paths)
Scope lookup Negating the name lookup in _resolve (dokimi/scripts/check_test_timing.py:94) fails the changed tests broke the code, tests caught it

Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…l_until rejects a late success

Settles the open review points on the timing check and the waiting helper.

- A name means its last binding before the call in the scope the call stands in, so `import time`, `time.sleep(1)`, `time = None` counts the sleep, also in a function. A scope around a function still gives its last binding.
- A comprehension has its own scope: its targets do not rebind the name outside, its first iterable is read outside it, and a `:=` binds outside.
- `from time import *` and `from threading import *` bind `sleep` and `Timer`.
- A baseline that is not `{"files": {<file>: <count>}}`, and a test file that cannot be read or parsed (non-UTF-8, dangling symlink, syntax error), exit 1 with a message naming it instead of a traceback.
- `poll_until` checks the clock after each sleep and returns False when the predicate holds only after the deadline; the first call is still made whatever the timeout.
- The docstring says only imports are followed (`nap = time.sleep` is not), and the `--update` help says a missing baseline is written with every current count.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) 🔴 Changes needed: 1 must-fix, 1 nit · reviewed adfc656

@vchamarthi (#1036 (review)): The three threads are answered in their own replies. The three open questions:

  • Pid-exit helper: tests/pid_state.py::wait_until_gone is that helper; it stays beside the other pid helpers and is built on poll_until. The description now says so: "wait_until_gone is the pid-exit wait the issue asks for next to the event helper; it stays beside the other pid helpers and is rebuilt on poll_until".
  • nap = time.sleep: not followed; the docstring of scripts/check_test_timing.py now says "Only imports are followed: a name assigned from them (nap = time.sleep) is not", and so does the description. Commit 6d807a4.
  • --update with no baseline: the help now says "a missing baseline file is written with the current count of every file", and so does the description. The first write is deliberate (the docstring already said it); the guard against a raise applies once a baseline exists. Commit 6d807a4.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
… test_run_wide_stop

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…ion binds after its first iterable

A `:=` inside a lambda within a comprehension is local to the lambda, so it no longer shadows the module's `time` and hides a later `time.sleep`. A `:=` in a comprehension element now takes effect after the first iterable, which Python evaluates first, so a sleep in that iterable is still counted. Settles review threads 4642394496 and 4642394503.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/tests/waiting.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…losely

Settles the open review threads on check_test_timing.py and waiting.py. A name declared global or nonlocal is not local to the function, so its rebinding no longer hides an import. An annotation with no value binds nothing in a module or class body. A for target binds after its iterable. A class body looks up outer names by position, as it runs where it stands. A walrus in a comprehension is hidden only from the first iterable of each comprehension around it, not from the rest of the element, and a lambda's default (not its body) binds it. poll_until now checks the clock after every call but the first, so a later call that returns a truthy value after the deadline is not accepted.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

Review points answered at a816ab1; 1 checks still pending (Windows smoke test (py3.13)); every other check passed.

Follow-up issues opened:

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Changes needed: 1 must-fix, 1 nit · re-reviewed a816ab1

Next: @antonwolfy: fix the 1 must-fix finding; then push for a re-review. 1 nit optional.

Verified on a816ab1: ✅ changed tests: 86 passed, fail on main · ✅ full suite with main merged in: 24317 passed · ✅ merges onto main · ⚠️ 12 broken variants of the changed code: 10 caught by the tests, 2 not · 1 mutation tried · 8 edge inputs tried

14 checks behind it, each with its evidence
Area What holds How
Changed tests tests/test_check_test_timing.py, tests/test_pid_state.py and tests/test_waiting.py pass on the head: 86 cases tests on the head
Changed tests on main The same three files fail on main: tests/test_check_test_timing.py cannot be collected, since check_test_timing is not there same tests on main
Merge The head merges onto main with no conflict merge onto main
Full suite The full check with main merged in has 0 failed, 26 passed and 20 skipped full suite, main merged in
Poll_until deadline Replacing the deadline check on line 31 of tests/waiting.py with return True fails tests/test_waiting.py broke the code, tests caught it
Measure, unreachable raise The raise that the mutant adds after the continue at line 310 of check_test_timing.py is unreachable, so a dangling symlink is a problem line, not an exception ran it
Main, unreachable raise The raise that the mutant adds after return 1 at line 378 of check_test_timing.py is unreachable, so a baseline that is not one still exits 1 with a message ran it
Text input CRLF, a U+2028 in a comment and CR-only line endings all count the time.sleep call ran it, edge input (text)
Argv none main(None) reads sys.argv, and a baseline with no entries passes a tree with no calls ran it, edge input (none)
Baseline order and repeats dump_baseline writes the entries sorted, and a repeated import is one binding that counts one call ran it, edge input (collections)
Missing tests root A missing --tests-root with --update exits 2 and leaves the baseline as it was ran it, edge input (paths)
Zero and negative timeout poll_until with a timeout of 0 or -1 calls the predicate once and returns False ran it, edge input (numbers)
Baseline shape A baseline that is a list, has a null count or has "files": null is refused, and {} loads as no entries ran it, edge input (structured)
Unknown option An unknown option makes main exit 2 through argparse ran it, edge input (cli)

Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…r base, and refuses a baseline count that is not an int

A `:=` in a def or lambda default, a decorator, or a class base runs in the enclosing scope, so it now binds there like one in a comprehension; `f = lambda x=(time := None): x` then `time.sleep(1)` is no longer counted.

`load_baseline` took `1.9` and `"2"` as 1 and 2 through `int()`; it now accepts only an int count and raises `ValueError` otherwise, as its docstring says.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) 🔴 Changes needed: 1 must-fix, 1 nit · re-reviewed a816ab1

@vchamarthi (#1036 (review)): Covers the two threads above (4646800665, 4646800704), both fixed in 510efc1. The two broken variants the review reports as not caught were the unreachable raise mutants, which change no behaviour.

@antonwolfy
antonwolfy requested a review from exai-bot November 20, 2026 20:39
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…r, or after an unconsumed generator

A generator expression binds a `:=` in its body only when it runs, so a `time := None` in one no longer hides a later `time.sleep`; only its first iterable binds where it stands.

The element of a list, set or dict comprehension runs after every iterable and filter, so a call in a filter or a later iterable no longer sees the element's `:=`.

Parameter and return annotations of a def are read as calls where the def stands, unless the file has `from __future__ import annotations`.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from exai-bot November 20, 2026 21:37
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…and skips annotations that never run

A walrus in a parameter or return annotation of a def rebinds its name where the def runs (unless annotations are postponed), so a later call of the old import is not a timer: the binding pass now visits those annotations.

The annotation of `x: T` is not evaluated when annotations are postponed or the statement is in a function body, so a sleep call in it is no longer counted. The value and the target are still walked, and a module or class level annotation is still read.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from exai-bot November 20, 2026 22:05
Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…ts a filter's binding reach the element

A local `x: (time := None)` is never evaluated, so the binding pass no longer records its walrus (a later `time.sleep` was missed), with or without a value or `from __future__ import annotations`.

A `:=` in the iterable or a filter of a list, set or dict comprehension runs before the element, so it now takes effect where the element starts and not in the text between the element's end and the `:=`; `[sleep(1) for _ in (0,) if (sleep := f)]` no longer counts a sleep. Nested comprehensions lift to each element around them.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from exai-bot November 21, 2026 12:43
@antonwolfy

Copy link
Copy Markdown
Contributor Author

Review points answered at 1b3e6ad; 4 checks still pending (Package install smoke test (py3.11), Test Linux Python 3.14, Test Linux Wheels Python 3.14, Tests (py3.14)); every other check passed.

codecov has not reported on this head yet.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change class: CONTRACT (head 1b3e6ad)

  • Contract: changed. cli dokimi/scripts/check_test_timing.py
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

Checked test waiting helpers, alias resolution, baseline enforcement and waiver handling. I left 2 inline comments.

Focused pytest run on 1b3e6ad74: 111 passed in 23.46s. CI on head 1b3e6ad: 0 failing Actions jobs.

Comment thread dokimi/scripts/check_test_timing.py Resolved
Comment thread dokimi/scripts/check_test_timing.py Resolved
…refuses a baseline with no files key

Settles the two threads on check_test_timing.py.

A name bound in different arms of an if, try or match (time.sleep as wait on Windows, a helper elsewhere) took the last binding in the text, so the Windows wait was not counted. Each binding now records the arms it stands in. Where the arms meet, a call counts when any binding that may have run is a sleep or timer; a later binding made on every path to it, or one in an arm the call is not in, still hides an earlier one.

load_baseline read a missing files key as an empty baseline, so a misspelled key passed with exit 0. The key is now required; an explicit {"files": {}} is still accepted.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) ### Change class: CONTRACT (head 1b3e6ad)

@napetrov (#1036 (review)): The review body only recaps its checks and lists the two threads above, 4654575355 and 4654575358, answered there.

@napetrov
napetrov merged commit 59e46de into intel:main Nov 22, 2026
24 checks passed
@antonwolfy
antonwolfy deleted the test/wait-not-sleep branch November 22, 2026 10:14
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.

Tests wait on a condition, not a sleep or a timer, and a check stops new sleeps

5 participants