Skip to content

Commit

Permalink
test: Undo thread_local g_insecure_rand_ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Dec 17, 2018
1 parent b545a6e commit fa0d3c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/test/test_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

FastRandomContext g_insecure_rand_ctx;

void CConnmanTest::AddNode(CNode& node)
{
LOCK(g_connman->cs_vNodes);
Expand All @@ -37,8 +39,6 @@ void CConnmanTest::ClearNodes()
g_connman->vNodes.clear();
}

thread_local FastRandomContext g_insecure_rand_ctx;

std::ostream& operator<<(std::ostream& os, const uint256& num)
{
os << num.ToString();
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_bitcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::os
return stream << static_cast<typename std::underlying_type<T>::type>(e);
}

thread_local extern FastRandomContext g_insecure_rand_ctx;
extern FastRandomContext g_insecure_rand_ctx;

static inline void SeedInsecureRand(bool deterministic = false)
{
Expand Down
11 changes: 7 additions & 4 deletions src/test/validation_block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
// create a bunch of threads that repeatedly process a block generated above at random
// this will create parallelism and randomness inside validation - the ValidationInterface
// will subscribe to events generated during block validation and assert on ordering invariance
boost::thread_group threads;
std::vector<std::thread> threads;
for (int i = 0; i < 10; i++) {
threads.create_thread([&blocks]() {
threads.emplace_back([&blocks]() {
bool ignored;
FastRandomContext insecure;
for (int i = 0; i < 1000; i++) {
auto block = blocks[InsecureRandRange(blocks.size() - 1)];
auto block = blocks[insecure.randrange(blocks.size() - 1)];
ProcessNewBlock(Params(), block, true, &ignored);
}

Expand All @@ -171,7 +172,9 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
});
}

threads.join_all();
for (auto& t : threads) {
t.join();
}
while (GetMainSignals().CallbacksPending() > 0) {
MilliSleep(100);
}
Expand Down

0 comments on commit fa0d3c4

Please sign in to comment.