qa: Drop recursive deletes from test code, add lint checks.#34439
qa: Drop recursive deletes from test code, add lint checks.#34439davidgumberg wants to merge 3 commits intobitcoin:masterfrom
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
734899a to
4f83671
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
Sounds reasonable, light concept ACK |
sedited
left a comment
There was a problem hiding this comment.
lgtm
The changes to the cache directory logic in the last two commits were not that straight forward to understand for me. Can you elaborate on them a bit in the commit messages?
4f83671 to
bba180f
Compare
Thanks for the feedback, I've (hopefully) improved the commit message for the one where I drop the |
Adds a lint check for `remove_all()` `fs::remove_all()`/`std::filesystem::remove_all()` is extremely dangerous, all user-facing instances of it have been removed, and it also deserves to be removed from the places in our test code where it is being used unnecessarily.
At the time this was added in bitcoin#10197, building the test cache took 21 seconds, as described in that PR, but this is no longer true, as demonstrated by running the functional test framework with and without the --keepcache arguments on master prior to this commit: ``` hyperfine --warmup 1 --export-markdown results.md --runs 3 \ -n 'without --keepcache' './build/test/functional/test_runner.py -j $(nproc)' \ -n 'with --keepcache' './build/test/functional/test_runner.py -j $(nproc) --keepcache' ``` | Command | Mean [s] | Min [s] | Max [s] | Relative | |:----------------------|---------------:|--------:|---:|---:| | `without --keepcache` | 76.373 ± 3.058 | 74.083 | 79.846 | 1.00 | | `with --keepcache` | 77.384 ± 1.836 | 75.952 | 79.454 | 1.01 ± 0.05 | As a consequence, this argument can be removed from the test runner and this also has the benefit of being able to use an RAII-like `tempfile.TemporaryDirectory` instead of having to clean up the cache manually at the end of test runs. bitcoin#10197: bitcoin#10197
`shutil.rmtree` is dangerous because it recursively deletes. There are not likely to be any issues with it's current uses, but it is possible that some of the assumptions being made now won't always be true, e.g. about what some of the variables being passed to `rmtree` represent. For some remaining uses of rmtree that can't be avoided for now, use `cleanup_dir` which asserts that the recursively deleted folder is a child of the the `tmpdir` of the test run. Otherwise, `tempfile.TemporaryDirectory` should be used which does it's own deleting on being garbage collected, or old fashioned unlinking and rmdir in the case of directories with known contents.
bba180f to
548dc81
Compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |
Both
fs::remove_allandshutil::rmtree()are a bit dangerous, and most of their uses are not necessary, this PR removes most instances of both.remove_all()is still used in insrc/test/util/setup_common.cppas part ofBasicTestingSetup::BasicTestingSetup's constructor and destructor, and it is used in the kernel test code'sTestDirectory:bitcoin/src/test/kernel/test_kernel.cpp
Lines 100 to 112 in 734899a
In both cases,
remove_allis likely necessary, but the kernel's test code is RAII, ideallyBasicTestingSetupcould be made similar in a follow-up or in this PR if reviewers think it is important.Similarly in the python code, most usage was unnecessary, but there are a few places where
rmtree()was necessary, I have added sanity checks to make sure these are inside of thetmpdirbefore doing recursive delete there.