Skip to content

Commit fa80b08

Browse files
author
MarcoFalke
committed
test: Revert to random path element
1 parent fa66e08 commit fa80b08

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/test/util/setup_common.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ using node::VerifyLoadedChainstate;
7575
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
7676

7777
constexpr inline auto TEST_DIR_PATH_ELEMENT{"test_common bitcoin"}; // Includes a space to catch possible path escape issues.
78+
/** Random context to get unique temp data dirs. Separate from m_rng, which can be seeded from a const env var */
79+
static FastRandomContext g_rng_temp_path;
7880

7981
struct NetworkSetup
8082
{
@@ -138,8 +140,12 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
138140

139141
const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""};
140142
if (!m_node.args->IsArgSet("-testdatadir")) {
141-
const auto now{TicksSinceEpoch<std::chrono::nanoseconds>(SystemClock::now())};
142-
m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / util::ToString(now);
143+
// To avoid colliding with a leftover prior datadir, and to allow
144+
// tests, such as the fuzz tests to run in several processes at the
145+
// same time, add a random element to the path. Keep it small enough to
146+
// avoid a MAX_PATH violation on Windows.
147+
const auto rand{HexStr(g_rng_temp_path.randbytes(10))};
148+
m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / rand;
143149
TryCreateDirectories(m_path_root);
144150
} else {
145151
// Custom data directory

0 commit comments

Comments
 (0)