Repository navigation
test(testkit): remove a test's scratch directory when it passes - #26
Merged
adammharris merged 1 commit intoNov 5, 2026
Merged
Conversation
`prov_testkit::scratch` named its directory by process id and removed only that path, so a green `cargo test --workspace` left 741 entries and 34 MB in the temp directory, and every run added more. Where the temp directory is a tmpfs, that is memory until the next reboot. `scratch` now returns a `Scratch`, a guard that derefs to `Path` and removes the directory on drop, unless the thread is panicking, so a failing test still leaves its state to be read. Every hand-written `temp_dir()` fixture moved onto it, and `Federation`, `Nested` and peer.rs's fixture hold the guard in place of a `Drop` that removed the directory on failure too. smoke.rs's backups go in a directory of their own rather than beside the fixture. Paths gain a per-process count: a guard removes what it holds, so two tests must never share one. Closes docs/tasks/tests-leave-their-fixtures-in-temp.md, shelved under Closed tasks.
adammharris
deleted the
agent/backlog-tests-leave-their-fixtures-in-temp
branch
November 5, 2026 22:25
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 changed
prov_testkit::scratchreturns aScratch, a guard that derefs toPathand removes the directory on drop. A panicking thread keeps the directory, so a failing test still leaves its state to be read.temp_dir()fixture moved onto it, about 30 files. Notemp_dir()call remains outsideprov-testkit.Federation,Nestedandpeer.rs's fixture now hold the guard. Their ownDropremoved the directory on failure too.smoke.rswrites its backups into a scratch directory of their own instead of beside the fixture.prov-<scope>-<tag>-<pid>-<n>). This goes beyond the task: a guard removes what it holds, so two tests sharing a path could now delete each other's directory.views.rs, for one, has two helpers building the sameprov-views-cli-<tag>name.scratchno longer claims a path stable across runs.Test-only: nothing a caller of prov can observe changes, so there is no
Behavioural-change:trailer.Why
A green
cargo test --workspaceleft 741 entries and 34 MB in the temp directory, and every run added more. On a tmpfs that is memory until the next reboot.For review
A guard dropped early still compiles, and the test then fails or reads a missing directory.
scratch(..).join("x")and a helper that returns a path derived from a guard it held both do this. The full run caught six such tests, all fixed here, and they are whylinked_shareandouter_and_nestednow return the guard as well. The doc comment onScratchwarns about it.A test that fails by returning
Errrather than panicking would lose its directory. I searched for test functions returningResultand found none.Closes
docs/tasks/tests-leave-their-fixtures-in-temp.md, shelved under Closed tasks.How it was verified
prov-testkitfor the three properties; the two that needed the change failed before it, and the third, keeping a failing test's directory, passed both before and after, since nothing removed directories then.ship ci: all 7 jobs passed. An earlier run failed clippy onlet_and_return, fixed here.TMPDIR=<empty dir> cargo test --workspaceon the committed tree: 1,241 passed, 0 failed, nothing left inTMPDIR.