-
Notifications
You must be signed in to change notification settings - Fork 39.2k
test: Revert to random path element #31317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,13 @@ using node::VerifyLoadedChainstate; | |
| 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. | ||
| /** 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; | ||
| static const bool g_rng_temp_path_init{[] { | ||
| // Must be initialized before any SeedRandomForTest | ||
| (void)g_rng_temp_path.rand64(); | ||
| return true; | ||
| }()}; | ||
|
|
||
| struct NetworkSetup | ||
| { | ||
|
|
@@ -132,14 +139,16 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts) | |
| } | ||
| } | ||
|
|
||
| // Use randomly chosen seed for deterministic PRNG, so that (by default) test | ||
| // data directories use a random name that doesn't overlap with other tests. | ||
| SeedRandomForTest(SeedRand::FIXED_SEED); | ||
|
|
||
| const std::string test_name{G_TEST_GET_FULL_NAME ? G_TEST_GET_FULL_NAME() : ""}; | ||
| if (!m_node.args->IsArgSet("-testdatadir")) { | ||
| const auto now{TicksSinceEpoch<std::chrono::nanoseconds>(SystemClock::now())}; | ||
| m_path_root = fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / test_name / util::ToString(now); | ||
| // To avoid colliding with a leftover prior datadir, and to allow | ||
| // 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); | ||
|
Comment on lines
+146
to
152
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about checking
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am not sure that running tests (or the setup of them) in a loop until they pass is a good approach. Generally, when there is an issue, it should be addressed, instead of being silently hidden.
Maybe a follow-up can do this? The goal of this pull request is to unbreak OSS-Fuzz (not sure if any other deployment is affected) by simply restoring what has been done for all previous releases in the unit tests.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Created this PR, let me know if you would prefer any changes or if you think my approach is incorrect! |
||
| } else { | ||
| // Custom data directory | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested cherrypicking 8e5f8a4 from #30737 on top of this PR to forward
RANDOM_CTX_SEEDon inside test/fuzz/test_runner.py.Ran this ~10 times:
Many of the failures come down to:
This proves to me that the latter part of this comment is not true. I would therefore suggest one of:
m_rngdirectly instead of reintroducingg_rng_temp_path.g_rng_temp_pathtruly non-deterministic (maybe through reverting part of 97e16f5, moving the seeding, haven't tested).g_rng_temp_path, so the other two alternatives would be preferable).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this issue is re-introduced.
It can also be tested on top of fa80b08 via something like:
RANDOM_CTX_SEED=21 FUZZ=utxo_total_supply ./bld-cmake/src/test/fuzz/fuzz -runs=10 -jobs=2 -workers=2I didn't want to fix it, as it was pre-existing and no one complained (at least OSS-Fuzz did not), whereas OSS-Fuzz did complain about the fixed issue.
However, as this is a trivial fix, I've added another commit to do so.
Let me know if this is acceptable. If not, my recommendation would be to move it to a follow-up to not delay this fix further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having
g_rng_temp_path_initbe called as soon as this compilation unit is included in a binary isn't ideal but still acceptable (BasicTestingSetupmay not be used in a given run).Good call on removing the defunct comment before
SeedRandomForTest()as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess it should be fine to move the init inside the
BasicTestingSetupconstructor, as long as it is before theSeedRandomForTest. I am happy to review a follow-up doing that, but I'll leave this as-is for now, due to the three acks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the robustness of the current solution. Never know where
SeedRandomForTestmight creep in inside unit/bench/fuzz. Please resolve this.