Repository navigation
test: wait on conditions instead of fixed sleeps (#1058) - #1111
Conversation
Thirteen test files slept a fixed time or ran a timer to wait for a child process, a zombie state, a marker file or the harness start, and flaked on a loaded runner. They now wait with poll_until or wait_until from tests/waiting.py: the pid helpers poll until the pid is gone, the interrupt tests in test_process.py interrupt once the child has handled its SIGTERM instead of after 0.3 s, and the SIGTERM reach test waits for the harness pid file. A failed wait names what it waited for. The sleeps and the one timer that stay carry a timing-ok reason: checks that nothing happened (the SIGHUP changed nothing, a killed helper wrote no marker), a thread-order jitter, a slow worker or slow call that is the subject of the test, the time a run that went on would use to start a queued question, and a SIGINT that has to land while the main thread blocks in open(), for which no event exists. The timing baseline is now empty. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 14 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1111 +/- ##
==========================================
- Coverage 96.08% 96.07% -0.02%
==========================================
Files 461 461
Lines 60836 60836
Branches 10517 10517
==========================================
- Hits 58457 58446 -11
- Misses 1473 1480 +7
- Partials 906 910 +4 🚀 New features to boost your workflow:
|
vchamarthi
left a comment
There was a problem hiding this comment.
Approving 772f349.
Checked: changed tests: 706 passed, pass on main too; full suite with main merged in: 37432 passed, its only failures are main's too; merges onto main.
Optional: 1 nit in line comments.
| "tests/test_typed_scorer.py": 1, | ||
| "tests/test_writers_stop_on_rejected_save.py": 2 | ||
| } | ||
| "files": {} |
There was a problem hiding this comment.
Nit, not blocking: The description says 22 sleeps and timers in 13 files; the removed baseline counts sum to 21.
Suggestion: Change 22 to 21 in the PR description.
Details
Input: the 13 files entries this diff removes: 2, 1, 1, 1, 1, 1, 2, 5, 2, 1, 1, 1, 2. Observed: they sum to 21. Expected: 21 in the description, which says 22.
Summary
#1058 asks to move the 22 sleeps and timers that
scripts/check_test_timing.pycounted in 13 files oftests/totests/waiting.py, starting with the files that flaked. Onmainthe baselinescripts/test_timing_baseline.jsonstill lists them:test_agent_sandbox.py2,test_process.py5,test_pid_state.py2,test_repo_reach.py2,test_writers_stop_on_rejected_save.py2, and one each intest_benchflow_harness.py,test_docker_cmd.py,test_example_runner_processes.py,test_judge_sequential_design.py,test_mutate_changed.py,test_task_harnesses.py,test_tool_preference.py,test_typed_scorer.py.tests/test_repo_batch_lifecycle.pyhas none left, as the issue's own baseline says. The issue's text saystests/waiting.pyand the checker exist only in open #1036; #1036 and #1060 are merged and both are onmain.The sleeps that waited for a child to die, a zombie state, a marker file or the harness start now wait on that condition with
poll_untilorwait_until. Sleeps that cannot become a wait stay with a# timing-ok: <reason>. The baseline is empty:python scripts/check_test_timing.pyreports0 sleep/Timer call(s) in 0 file(s).Closes #1058
Changes
tests/test_process.py:_gone_soonand_wait_forarepoll_untilandwait_untilcalls (a file that never appears now fails withgave up after 10.0 s waiting for <path> to be written). The two interrupt tests that slept 0.3 s before raisingKeyboardInterruptnow interrupt once the child has written the marker its SIGTERM handler writes, so the interrupt lands inside the grace on a slow runner too.tests/test_pid_state.py: the two wait loops for the child'scmdlineand for the zombie state arewait_untilcalls.tests/test_repo_reach.py: the wait for the harness pid file ispoll_until, with the same assertion message as before.tests/test_agent_sandbox.py,tests/test_example_runner_processes.py,tests/test_mutate_changed.py,tests/test_task_harnesses.py,tests/test_benchflow_harness.py: loops that slept until a pid was gone arepoll_untilorwait_until; the benchflow one fails withgave up after 5 s waiting for the child of the timed-out bench process to be gone.tests/test_writers_stop_on_rejected_save.py: the wait for the.rejectedfile ispoll_until.# timing-okand a reason:test_repo_reach.py(the killed helper must not have written its marker 3 s later) andtest_agent_sandbox.py(the surviving child would write its marker after 4 s) are checks that nothing happened, andtest_process.py(the SIGHUP changed nothing);test_judge_sequential_design.pyis a jitter that shuffles thread order;test_tool_preference.pyholds a worker back as the subject of the test;test_typed_scorer.pyneeds each call to take measurable time;test_writers_stop_on_rejected_save.pykeeps the 0.2 s a run that went on would use to start a queued question;test_docker_cmd.pyis a SIGINT timer that must land while the main thread blocks inopen()of a FIFO, and nothing shows that it does.scripts/test_timing_baseline.json: lowered withcheck_test_timing.py --update; all 13 files are dropped.dokimi/tests/anddokimi/scripts/change, andmake ci-localasks for none.__import__("time").sleep(0.05)intests/test_container_agent.py) is tracked in check_test_timing:__import__("time").sleep(...)is not counted, so test_container_agent.py still polls with a fixed sleep #1110.Risk
Test-only. A wait that gives up now ends in
pytest.failnaming what it waited for instead of anAssertionErroror a failed later assertion. No test is removed, no assertion dropped and nopytest.raiseswidened (scripts/check_test_narrowing.py: no existing test narrowed).Testing
On Linux, at
772f3492(onmain06341ca):make ci-local: 38 passed, 0 failed, 14 skipped (steps that need a tool or a trigger this run lacks: semgrep, micromamba, the atheris fuzz run, the intel-ci matrix, the jobs that run only off a PR, the CLI-surface package step). 25979 tests passed, 19 skipped; the changed-lines coverage step reports no lines with coverage information, since only tests changed.test_process.pyandtest_pid_state.py(89 tests),test_repo_reach.py(91), and the ten other files withtest_check_test_timing.py(652).test_pid_state.py::test_running_zombie_and_reaped_child_are_told_apart(cmdline never matches:gave up after 30 s waiting for the child to exec; zombie state never reached:... waiting for the killed child to become a zombie),test_repo_reach.py::test_sigterm_to_the_cli_kills_the_harness_and_its_helper(pid file never seen:the harness never started),test_process.py(_wait_fornever true:gave up after 10.0 s waiting for ... to be written;_gone_sooninverted:assert _gone_soon(...)fails),test_benchflow_harness.py::test_run_bench_kills_the_process_group_on_timeout(gave up after 5 s waiting for the child of the timed-out bench process to be gone),test_example_runner_processes.py::test_subprocess_background_job_is_killed_on_exitandtest_task_harnesses.py::test_command_harness_leaves_nothing_of_the_agent_running(_gone_soon/_pid_gonenever true: the pid assertion fails).main's code under any load tried, so this change is not shown to cure one here: ten parallel runs of the three flaky files (--timeout=20) passed 180 tests in each; 20 runs oftest_pid_state.pyandtest_repo_reach.pybeside 32 busypython -c "while 1: pass"processes (twice the 16 cores) passed 97 tests in each; 20 runs oftest_process.pyunder the same 32 processes passed 83 tests in each; 20 runs of the two interrupt tests oftest_process.pywith the child's SIGTERM handler delayed by 0.6 s passed 2 in each, onmain's code and at the tip alike, because after the interrupt the second wait still runs out the grace.test_writers_stop_on_rejected_save.pyis not shown to depend on its new wait: withpoll_until(rejected.exists)replaced by a call that returns at once all 4 tests still pass, so the 0.2 stiming-oksleep is what carries the test and the wait is slack there.Open questions
None.
Revert
A plain revert restores the fixed sleeps and the old baseline. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)