mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-17 11:07:00 +02:00
Merge bitcoin/bitcoin#34439: qa: Drop recursive deletes from test code, add lint checks.
0d1301b47atest: functional: drop rmtree usage and add lint check (David Gumberg)8bfb422de8test: functional: drop unused --keepcache argument (David Gumberg)a7e4a59d6dqa: Remove all instances of `remove_all` except test cleanup (David Gumberg) Pull request description: Both `fs::remove_all` and `shutil::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 in `src/test/util/setup_common.cpp` as part of `BasicTestingSetup::BasicTestingSetup`'s constructor and destructor, and it is used in the kernel test code's [`TestDirectory`](4ae00e9a71/src/test/kernel/test_kernel.cpp (L100-L112)):734899a4c4/src/test/kernel/test_kernel.cpp (L100-L112)In both cases, `remove_all` is likely necessary, but the kernel's test code is RAII, ideally `BasicTestingSetup` could 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 the `tmpdir` before doing recursive delete there. ACKs for top commit: achow101: ACK0d1301b47ahodlinator: ACK0d1301b47asedited: ACK0d1301b47aTree-SHA512: da8ca23846b73eff0eaff61a5f80ba1decf63db783dcd86b25f88f4862ae28816fc9e2e9ee71283ec800d73097b1cfae64e3c5ba0e991be69c200c6098f24d6e
This commit is contained in:
@@ -10,6 +10,7 @@ import argparse
|
||||
from datetime import datetime, timezone
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import pdb
|
||||
import random
|
||||
@@ -331,7 +332,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
h.flush()
|
||||
rpc_logger.removeHandler(h)
|
||||
if cleanup_tree_on_exit:
|
||||
shutil.rmtree(self.options.tmpdir)
|
||||
self.cleanup_folder(self.options.tmpdir)
|
||||
|
||||
self.nodes.clear()
|
||||
return exit_code
|
||||
@@ -1031,3 +1032,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
return result
|
||||
except ImportError:
|
||||
self.log.warning("sqlite3 module not available, skipping tests that inspect the database")
|
||||
|
||||
def cleanup_folder(self, _path):
|
||||
path = Path(_path)
|
||||
if not path.is_relative_to(self.options.tmpdir):
|
||||
raise AssertionError(f"Trying to delete #{path} outside of #{self.options.tmpdir}")
|
||||
shutil.rmtree(path)
|
||||
|
||||
@@ -11,7 +11,6 @@ from enum import Enum
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
@@ -20,7 +19,6 @@ import time
|
||||
import urllib.parse
|
||||
import collections
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
@@ -163,8 +161,8 @@ class TestNode():
|
||||
self.args.append("-ipcbind=unix")
|
||||
else:
|
||||
# Work around default CI path exceeding maximum socket path length.
|
||||
self.ipc_tmp_dir = pathlib.Path(tempfile.mkdtemp(prefix="test-ipc-"))
|
||||
self.ipc_socket_path = self.ipc_tmp_dir / "node.sock"
|
||||
self.ipc_tmp_dir = tempfile.TemporaryDirectory(prefix="test-ipc-")
|
||||
self.ipc_socket_path = Path(self.ipc_tmp_dir.name) / "node.sock"
|
||||
self.args.append(f"-ipcbind=unix:{self.ipc_socket_path}")
|
||||
|
||||
if self.version_is_at_least(190000):
|
||||
@@ -248,9 +246,6 @@ class TestNode():
|
||||
# this destructor is called.
|
||||
print(self._node_msg("Cleaning up leftover process"), file=sys.stderr)
|
||||
self.process.kill()
|
||||
if self.ipc_tmp_dir:
|
||||
print(self._node_msg(f"Cleaning up ipc directory {str(self.ipc_tmp_dir)!r}"))
|
||||
shutil.rmtree(self.ipc_tmp_dir)
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
|
||||
|
||||
Reference in New Issue
Block a user