Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_block_tests.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) { | ||||
} | } | ||||
TestSubscriber sub(initial_tip->GetBlockHash()); | TestSubscriber sub(initial_tip->GetBlockHash()); | ||||
RegisterValidationInterface(&sub); | RegisterValidationInterface(&sub); | ||||
// create a bunch of threads that repeatedly process a block generated above | // create a bunch of threads that repeatedly process a block generated above | ||||
// at random this will create parallelism and randomness inside validation - | // at random this will create parallelism and randomness inside validation - | ||||
// the ValidationInterface will subscribe to events generated during block | // the ValidationInterface will subscribe to events generated during block | ||||
// validation and assert on ordering invariance | // validation and assert on ordering invariance | ||||
boost::thread_group threads; | std::vector<std::thread> threads; | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
threads.create_thread([&config, &blocks]() { | threads.emplace_back([&config, &blocks]() { | ||||
bool tlignored; | bool tlignored; | ||||
FastRandomContext insecure; | |||||
for (int j = 0; j < 1000; j++) { | for (int j = 0; j < 1000; j++) { | ||||
auto block = blocks[InsecureRandRange(blocks.size() - 1)]; | auto block = blocks[insecure.randrange(blocks.size() - 1)]; | ||||
ProcessNewBlock(config, block, true, &tlignored); | ProcessNewBlock(config, block, true, &tlignored); | ||||
} | } | ||||
// to make sure that eventually we process the full chain - do it | // to make sure that eventually we process the full chain - do it | ||||
// here | // here | ||||
for (auto block : blocks) { | for (auto block : blocks) { | ||||
if (block->vtx.size() == 1) { | if (block->vtx.size() == 1) { | ||||
bool processed = | bool processed = | ||||
ProcessNewBlock(config, block, true, &tlignored); | ProcessNewBlock(config, block, true, &tlignored); | ||||
assert(processed); | assert(processed); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
threads.join_all(); | for (auto &t : threads) { | ||||
t.join(); | |||||
} | |||||
while (GetMainSignals().CallbacksPending() > 0) { | while (GetMainSignals().CallbacksPending() > 0) { | ||||
MilliSleep(100); | MilliSleep(100); | ||||
} | } | ||||
UnregisterValidationInterface(&sub); | UnregisterValidationInterface(&sub); | ||||
BOOST_CHECK_EQUAL(sub.m_expected_tip, chainActive.Tip()->GetBlockHash()); | BOOST_CHECK_EQUAL(sub.m_expected_tip, chainActive.Tip()->GetBlockHash()); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |