Repository navigation
Tests: the lint, screenshot and replay runs delete their temp trees - #1244
Merged
Merged
Conversation
Three test drivers left folders in $TMPDIR: about 940 of them, about 10 GiB, on one Mac. - tests/test_harness.py: each DepGates test copies the lint inputs into `_check_deps_tree_*` (40 MB) and removes it with addCleanup. A completed run removes every copy; a run stopped by SIGTERM does not, because the default action ends Python before any cleanup runs. `make check` stops the harness branch with SIGTERM when its sibling fails (check-parallel is fail-fast), and up to min(8, cpus) copies are in flight. `__main__` now turns SIGTERM and SIGHUP into KeyboardInterrupt, which `_ParallelSuite` already unwinds. - tools/screenshots.py, tools/hud_preview.py: the same for a scene's `plxnative-shot-<scene>-*` instance root (up to 0.7 GiB for a virtual capture) and the `plxnative-shots-*` staging directory; SIGTERM and SIGHUP now exit through the existing `finally` blocks, and subprocess.run kills the simulator. - tests/replay_fixtures.py: a `plxnative-replay-gate-*` folder the driver made for itself was printed as evidence and never removed; it is now removed after a clean run and kept (and named) when a replay failed. `--output` is never removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ial run unittest skips doCleanups when a KeyboardInterrupt ends a test, so a run on the main thread (a named DepGates test, PLX_TEST_JOBS=1, a one-CPU host) left its `_check_deps_tree_*` behind on Ctrl-C or SIGTERM. DepGates.run now runs the cleanups and re-raises; the probe covers both the pool and the serial path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ve their test A DepGates test still running on the pool when the run is stopped could start one more ~11 s check-deps.sh that the group SIGTERM never reached, outlast check-parallel's 10 s grace and be SIGKILLed with its copy on disk. `tree` now raises once `_ParallelSuite` has been interrupted, and every gate run builds its command from it. The probe holds its tests until the stop and requires that none runs on; its held tests also have a deadline, and the fake "never settles" simulator execs its sleep so the timeout kills it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What leaked
$TMPDIRon the owner's Mac held about 940 folders, about 10 GiB, left by three test drivers. Each had a cause that is not the one first suspected, so each was reproduced before it was fixed._check_deps_tree_*tests/test_harness.py,DepGates.treeplxnative-shot-<scene>-*tools/screenshots.py,captureplxnative-replay-gate-*tests/replay_fixtures.py,mainOut of scope, left alone:
plxnative-relcheck-target(a deliberately reused cargo target dir). A few unrelatedtmp*folders (plxnative-crash-evidence,case_a.stderr.log) also remain after a harness run; they are other tests and tiny.Causes and fixes
_check_deps_tree_*: a run stopped by SIGTERM, not a failingrmtreeThe suspicion (
rmtree(ignore_errors=True)failing on a read-only entry) was tested and does not hold:TREE_INPUTSare non-writable.TMPDIRprivate:Ran 554 tests in 462.430s,OK, and zero_check_deps_tree_*left. A normal run does not leak.DepGatesrun that the tool killed at its time limit left exactly one:_check_deps_tree_683365o8.The cause is that
make checkruns the harness as a fail-fast branch (tools/check-parallel.py,Branch.stop:killpgSIGTERM, 10 s, SIGKILL), and Python's default SIGTERM action ends the process before anyaddCleanupruns._ParallelSuitehasmin(8, cpus)workers, each holding a copy, which is the batch of 8 seen at 15:43. Ctrl-C was already safe: aKeyboardInterruptunwinds_ParallelSuiteand each running test cleans up.Fix (
tests/test_harness.py):_unwind_on_termination(), called from__main__, turns SIGTERM and SIGHUP intoKeyboardInterrupt. Notsys.exit: unittest'stestPartExecutorrecords aSystemExitout of a test body as that test's error and carries on.DepGates.runrunsdoCleanups()and re-raises onKeyboardInterrupt, because unittest skips the cleanups then. This covers a serial run (a named test,PLX_TEST_JOBS=1), which left a tree on interrupt even with the handler.DepGates.treeraises once_ParallelSuitehas been interrupted, and every gate run builds its command fromtree. A test still on the pool therefore starts no further ~11 scheck-deps.sh: one the group signal never reached would outlast the 10 s grace and be SIGKILLed with its copy on disk.Not fixed: SIGKILL cannot be handled, so a
kill -9, or a teardown that outlasts the 10 s grace, still leaves the copies in flight.plxnative-shot-<scene>-*: SIGTERM skips thefinallycapture'sfinallyremoves the instance root on every exit that unwinds: a settled capture, a refused one, a timeout and a failingprepareall leave nothing (tested). The only exit that skips thefinallyis a kill, and that is the cause I could reproduce: SIGTERM's default action runs nofinallyand leaves the simulator running, so the root (andrender_set'splxnative-shots-*staging directory) stays. The leftover scene names (same-scene-background-cycle-*,reference,minimal,pr13-01) are HUD-preview scenes, a long run that a tool timeout would stop. A virtual capture'sframes.rgbis 1920x1080x3x120 bytes, which is the 0.7 GiB.I also probed a simulator that leaves a non-writable subdirectory:
rmtree(ignore_errors=True)does fail silently then. No non-test Rust code makes a directory under the runtime root non-writable (the onlyset_permissionscalls with0o500/0o400are in test code), so I left that path alone.Fix:
screenshots.unwind_on_signals()(SIGTERM and SIGHUP raiseSystemExit(128 + n), the idiomtools/build-bench.pyuses), called fromscreenshots.mainandhud_preview.main. TheSystemExitpasses throughrender_set'sexcept Exception,subprocess.runkills the simulator it is waiting on, and the existingfinallyblocks remove the root and the staging directory.plxnative-replay-gate-*: printed as evidence, never removedmainmade the folder withmkdtemp, printed it as "evidence" and never removed it, even when every replay passed. It is now removed after a clean run and kept, with its path printed, when a replay failed. A folder passed with--outputis never removed (CI passes--output "$RUNNER_TEMP/plxnative-replay", so the artifact upload is unaffected). If the removal itself fails the folder is kept and the error printed to stderr instead of being hidden. The module docstring ("Evidence roots are retained") is updated.Red, then green
Each test below was run against the unfixed code first.
tests/test_harness.py DepGatesLeaveNothingWhenStoppedAssertionError: Lists differ: ['_check_deps_tree_0dmp_pux', '_check_deps_tree_m_vxyw4q', '_check_deps_tree_mlmamsiz'] != [],FAILED (failures=1)(SIGTERM to 3 tests on a pool); the serial subtest alone left_check_deps_tree__hzlrhhowithoutDepGates.run; a test that runs on after the stop leftran-after-stopwithout thetreecheckRan 1 test,OKtests/test_hud_capture.py InstanceRootLists differ: ['plxnative-shots-_0f8qu14', 'plxnative-shot-home-xf2osssg'] != [],Ran 5 tests,FAILED (failures=1)Ran 5 tests,OKtests/test_hud_preview.pyFalse is not true : the default action ends the process at oncefor SIGTERM and SIGHUP,Ran 8 tests,FAILED (failures=2)Ran 8 tests,OKtests/test_replay_fixtures.py OutputFolderTestsLists differ: [PosixPath('.../plxnative-replay-gate-dbwwtmhz')] != [],Ran 16 tests,FAILED (failures=1)Ran 16 tests,OKThe screenshot test runs the real
screenshots.mainas a child process against a fake simulator script and a fake mock server (the real catalogue mock takes about 36 s to start), sends it SIGTERM, and requires an empty$TMPDIRand a dead simulator. The probe for the harness does the same with aDepGatessubclass that holds its private copy.Other runs on the final tree:
tests/test_demo_library.pyRan 167 tests,OK (skipped=5);tests/test_site_stills.pyRan 28 tests,OK; the wholetests/test_harness.pywith a privateTMPDIR,Ran 555 tests,OK, zero_check_deps_tree_*left.make check, cargo and the simulator were not run; CI is the gate.🤖 Generated with Claude Code