test: Revert to random path element

This commit is contained in:
MarcoFalke 2024-11-18 14:22:22 +01:00
parent fa66e0887c
commit fa80b08fef
No known key found for this signature in database

View file

@ -75,6 +75,8 @@ using node::VerifyLoadedChainstate;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr; const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
constexpr inline auto TEST_DIR_PATH_ELEMENT{"test_common bitcoin"}; // Includes a space to catch possible path escape issues. constexpr inline auto TEST_DIR_PATH_ELEMENT{"test_common bitcoin"}; // Includes a space to catch possible path escape issues.
/** Random context to get unique temp data dirs. Separate from m_rng, which can be seeded from a const env var */
static FastRandomContext g_rng_temp_path;
struct NetworkSetup struct NetworkSetup
{ {
@ -138,8 +140,12 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""}; const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""};
if (!m_node.args->IsArgSet("-testdatadir")) { if (!m_node.args->IsArgSet("-testdatadir")) {
const auto now{TicksSinceEpoch<std::chrono::nanoseconds>(SystemClock::now())}; // To avoid colliding with a leftover prior datadir, and to allow
m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / util::ToString(now); // tests, such as the fuzz tests to run in several processes at the
// same time, add a random element to the path. Keep it small enough to
// avoid a MAX_PATH violation on Windows.
const auto rand{HexStr(g_rng_temp_path.randbytes(10))};
m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / rand;
TryCreateDirectories(m_path_root); TryCreateDirectories(m_path_root);
} else { } else {
// Custom data directory // Custom data directory