test: Use CCheckQueue local thread pool

This commit is contained in:
Hennadii Stepanov 2020-08-21 09:24:32 +03:00
parent 01511776ac
commit dba30695fc
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
2 changed files with 14 additions and 45 deletions

View File

@ -148,10 +148,7 @@ typedef CCheckQueue<FrozenCleanupCheck> FrozenCleanup_Queue;
static void Correct_Queue_range(std::vector<size_t> range) static void Correct_Queue_range(std::vector<size_t> range)
{ {
auto small_queue = MakeUnique<Correct_Queue>(QUEUE_BATCH_SIZE); auto small_queue = MakeUnique<Correct_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg; small_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
for (auto x = 0; x < SCRIPT_CHECK_THREADS; ++x) {
tg.create_thread([&]{small_queue->Thread();});
}
// Make vChecks here to save on malloc (this test can be slow...) // Make vChecks here to save on malloc (this test can be slow...)
std::vector<FakeCheckCheckCompletion> vChecks; std::vector<FakeCheckCheckCompletion> vChecks;
for (const size_t i : range) { for (const size_t i : range) {
@ -168,8 +165,7 @@ static void Correct_Queue_range(std::vector<size_t> range)
BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i); BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i);
} }
} }
tg.interrupt_all(); small_queue->StopWorkerThreads();
tg.join_all();
} }
/** Test that 0 checks is correct /** Test that 0 checks is correct
@ -212,11 +208,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random)
BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
{ {
auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE); auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE);
fail_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
boost::thread_group tg;
for (auto x = 0; x < SCRIPT_CHECK_THREADS; ++x) {
tg.create_thread([&]{fail_queue->Thread();});
}
for (size_t i = 0; i < 1001; ++i) { for (size_t i = 0; i < 1001; ++i) {
CCheckQueueControl<FailingCheck> control(fail_queue.get()); CCheckQueueControl<FailingCheck> control(fail_queue.get());
@ -237,18 +229,14 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
BOOST_REQUIRE(success); BOOST_REQUIRE(success);
} }
} }
tg.interrupt_all(); fail_queue->StopWorkerThreads();
tg.join_all();
} }
// Test that a block validation which fails does not interfere with // Test that a block validation which fails does not interfere with
// future blocks, ie, the bad state is cleared. // future blocks, ie, the bad state is cleared.
BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
{ {
auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE); auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg; fail_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
for (auto x = 0; x < SCRIPT_CHECK_THREADS; ++x) {
tg.create_thread([&]{fail_queue->Thread();});
}
for (auto times = 0; times < 10; ++times) { for (auto times = 0; times < 10; ++times) {
for (const bool end_fails : {true, false}) { for (const bool end_fails : {true, false}) {
@ -263,8 +251,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
BOOST_REQUIRE(r != end_fails); BOOST_REQUIRE(r != end_fails);
} }
} }
tg.interrupt_all(); fail_queue->StopWorkerThreads();
tg.join_all();
} }
// Test that unique checks are actually all called individually, rather than // Test that unique checks are actually all called individually, rather than
@ -273,11 +260,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
{ {
auto queue = MakeUnique<Unique_Queue>(QUEUE_BATCH_SIZE); auto queue = MakeUnique<Unique_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg; queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
for (auto x = 0; x < SCRIPT_CHECK_THREADS; ++x) {
tg.create_thread([&]{queue->Thread();});
}
size_t COUNT = 100000; size_t COUNT = 100000;
size_t total = COUNT; size_t total = COUNT;
@ -300,8 +283,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
} }
BOOST_REQUIRE(r); BOOST_REQUIRE(r);
} }
tg.interrupt_all(); queue->StopWorkerThreads();
tg.join_all();
} }
@ -313,10 +295,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
{ {
auto queue = MakeUnique<Memory_Queue>(QUEUE_BATCH_SIZE); auto queue = MakeUnique<Memory_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg; queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
for (auto x = 0; x < SCRIPT_CHECK_THREADS; ++x) {
tg.create_thread([&]{queue->Thread();});
}
for (size_t i = 0; i < 1000; ++i) { for (size_t i = 0; i < 1000; ++i) {
size_t total = i; size_t total = i;
{ {
@ -335,8 +314,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
} }
BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U); BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U);
} }
tg.interrupt_all(); queue->StopWorkerThreads();
tg.join_all();
} }
// Test that a new verification cannot occur until all checks // Test that a new verification cannot occur until all checks
@ -344,11 +322,8 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
{ {
auto queue = MakeUnique<FrozenCleanup_Queue>(QUEUE_BATCH_SIZE); auto queue = MakeUnique<FrozenCleanup_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
bool fails = false; bool fails = false;
for (auto x = 0; x < SCRIPT_CHECK_THREADS; ++x) { queue->StartWorkerThreads(SCRIPT_CHECK_THREADS);
tg.create_thread([&]{queue->Thread();});
}
std::thread t0([&]() { std::thread t0([&]() {
CCheckQueueControl<FrozenCleanupCheck> control(queue.get()); CCheckQueueControl<FrozenCleanupCheck> control(queue.get());
std::vector<FrozenCleanupCheck> vChecks(1); std::vector<FrozenCleanupCheck> vChecks(1);
@ -378,9 +353,8 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
FrozenCleanupCheck::cv.notify_one(); FrozenCleanupCheck::cv.notify_one();
// Wait for control to finish // Wait for control to finish
t0.join(); t0.join();
tg.interrupt_all();
tg.join_all();
BOOST_REQUIRE(!fails); BOOST_REQUIRE(!fails);
queue->StopWorkerThreads();
} }
@ -445,4 +419,3 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
} }
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -427,12 +427,10 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
// check all inputs concurrently, with the cache // check all inputs concurrently, with the cache
PrecomputedTransactionData txdata(tx); PrecomputedTransactionData txdata(tx);
boost::thread_group threadGroup;
CCheckQueue<CScriptCheck> scriptcheckqueue(128); CCheckQueue<CScriptCheck> scriptcheckqueue(128);
CCheckQueueControl<CScriptCheck> control(&scriptcheckqueue); CCheckQueueControl<CScriptCheck> control(&scriptcheckqueue);
for (int i=0; i<20; i++) scriptcheckqueue.StartWorkerThreads(20);
threadGroup.create_thread(std::bind(&CCheckQueue<CScriptCheck>::Thread, std::ref(scriptcheckqueue)));
std::vector<Coin> coins; std::vector<Coin> coins;
for(uint32_t i = 0; i < mtx.vin.size(); i++) { for(uint32_t i = 0; i < mtx.vin.size(); i++) {
@ -454,9 +452,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
bool controlCheck = control.Wait(); bool controlCheck = control.Wait();
assert(controlCheck); assert(controlCheck);
scriptcheckqueue.StopWorkerThreads();
threadGroup.interrupt_all();
threadGroup.join_all();
} }
SignatureData CombineSignatures(const CMutableTransaction& input1, const CMutableTransaction& input2, const CTransactionRef tx) SignatureData CombineSignatures(const CMutableTransaction& input1, const CMutableTransaction& input2, const CTransactionRef tx)