Skip to content

Commit e122309

Browse files
committed
Merge bitcoin/bitcoin#31317: test: Revert to random path element
faaaf59 test: Make g_rng_temp_path rand, not dependent on SeedRandomForTest (MarcoFalke) fa80b08 test: Revert to random path element (MarcoFalke) Pull request description: The randomness in the path element is required to allow a single fuzz test to run in parallel. Previous releases used a uint256 random value, but 10 random bytes should be sufficient as well, while avoiding a `MAX_PATH` violation on Windows. The issue was introduced by myself, by suggesting to use the current time in bitcoin/bitcoin#31000 (comment). ACKs for top commit: kevkevinpal: reACK bitcoin/bitcoin@faaaf59 hodlinator: ACK faaaf59 tdb3: re ACK faaaf59 dergoegge: ACK faaaf59 Tree-SHA512: f12256c8b353618291030f71bf36eab97a25ffeaa28e36a5f2c6718dfc1fbbc8548c71475edec53d59026f2a779a05778db83f0530dd3e1d1faf6e4fc0ee7d70
2 parents 2666d83 + faaaf59 commit e122309

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/test/util/setup_common.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ 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;
80+
static const bool g_rng_temp_path_init{[] {
81+
// Must be initialized before any SeedRandomForTest
82+
(void)g_rng_temp_path.rand64();
83+
return true;
84+
}()};
7885

7986
struct NetworkSetup
8087
{
@@ -132,14 +139,16 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
132139
}
133140
}
134141

135-
// Use randomly chosen seed for deterministic PRNG, so that (by default) test
136-
// data directories use a random name that doesn't overlap with other tests.
137142
SeedRandomForTest(SeedRand::FIXED_SEED);
138143

139144
const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""};
140145
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);
146+
// To avoid colliding with a leftover prior datadir, and to allow
147+
// tests, such as the fuzz tests to run in several processes at the
148+
// same time, add a random element to the path. Keep it small enough to
149+
// avoid a MAX_PATH violation on Windows.
150+
const auto rand{HexStr(g_rng_temp_path.randbytes(10))};
151+
m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / rand;
143152
TryCreateDirectories(m_path_root);
144153
} else {
145154
// Custom data directory

0 commit comments

Comments
 (0)