Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkqueue_tests.cpp
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** Test that random numbers of checks are correct | /** Test that random numbers of checks are correct | ||||
*/ | */ | ||||
BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) { | BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) { | ||||
std::vector<size_t> range; | std::vector<size_t> range; | ||||
range.reserve(100000 / 1000); | range.reserve(100000 / 1000); | ||||
for (size_t i = 2; i < 100000; | for (size_t i = 2; i < 100000; | ||||
i += std::max((size_t)1, (size_t)InsecureRandRange(std::min( | i += std::max((size_t)1, (size_t)InsecureRandRange(std::min( | ||||
(size_t)1000, ((size_t)100000) - i)))) | (size_t)1000, ((size_t)100000) - i)))) { | ||||
range.push_back(i); | range.push_back(i); | ||||
} | |||||
Correct_Queue_range(range); | Correct_Queue_range(range); | ||||
} | } | ||||
/** Test that failing checks are caught */ | /** Test that failing checks are caught */ | ||||
BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) { | BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) { | ||||
auto fail_queue = | auto fail_queue = | ||||
std::unique_ptr<Failing_Queue>(new Failing_Queue{QUEUE_BATCH_SIZE}); | std::unique_ptr<Failing_Queue>(new Failing_Queue{QUEUE_BATCH_SIZE}); | ||||
boost::thread_group tg; | boost::thread_group tg; | ||||
for (auto x = 0; x < nScriptCheckThreads; ++x) { | for (auto x = 0; x < nScriptCheckThreads; ++x) { | ||||
tg.create_thread([&] { fail_queue->Thread(); }); | 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()); | ||||
size_t remaining = i; | size_t remaining = i; | ||||
while (remaining) { | while (remaining) { | ||||
size_t r = InsecureRandRange(10); | size_t r = InsecureRandRange(10); | ||||
std::vector<FailingCheck> vChecks; | std::vector<FailingCheck> vChecks; | ||||
vChecks.reserve(r); | vChecks.reserve(r); | ||||
for (size_t k = 0; k < r && remaining; k++, remaining--) | for (size_t k = 0; k < r && remaining; k++, remaining--) { | ||||
vChecks.emplace_back(remaining == 1); | vChecks.emplace_back(remaining == 1); | ||||
} | |||||
control.Add(vChecks); | control.Add(vChecks); | ||||
} | } | ||||
bool success = control.Wait(); | bool success = control.Wait(); | ||||
if (i > 0) { | if (i > 0) { | ||||
BOOST_REQUIRE(!success); | BOOST_REQUIRE(!success); | ||||
} else if (i == 0) { | } else if (i == 0) { | ||||
BOOST_REQUIRE(success); | BOOST_REQUIRE(success); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) { | ||||
size_t COUNT = 100000; | size_t COUNT = 100000; | ||||
size_t total = COUNT; | size_t total = COUNT; | ||||
{ | { | ||||
CCheckQueueControl<UniqueCheck> control(queue.get()); | CCheckQueueControl<UniqueCheck> control(queue.get()); | ||||
while (total) { | while (total) { | ||||
size_t r = InsecureRandRange(10); | size_t r = InsecureRandRange(10); | ||||
std::vector<UniqueCheck> vChecks; | std::vector<UniqueCheck> vChecks; | ||||
for (size_t k = 0; k < r && total; k++) | for (size_t k = 0; k < r && total; k++) { | ||||
vChecks.emplace_back(--total); | vChecks.emplace_back(--total); | ||||
} | |||||
control.Add(vChecks); | control.Add(vChecks); | ||||
} | } | ||||
} | } | ||||
bool r = true; | bool r = true; | ||||
BOOST_REQUIRE_EQUAL(UniqueCheck::results.size(), COUNT); | BOOST_REQUIRE_EQUAL(UniqueCheck::results.size(), COUNT); | ||||
for (size_t i = 0; i < COUNT; ++i) | for (size_t i = 0; i < COUNT; ++i) { | ||||
r = r && UniqueCheck::results.count(i) == 1; | r = r && UniqueCheck::results.count(i) == 1; | ||||
} | |||||
BOOST_REQUIRE(r); | BOOST_REQUIRE(r); | ||||
tg.interrupt_all(); | tg.interrupt_all(); | ||||
tg.join_all(); | tg.join_all(); | ||||
} | } | ||||
// Test that blocks which might allocate lots of memory free their memory | // Test that blocks which might allocate lots of memory free their memory | ||||
// aggressively. | // aggressively. | ||||
// | // | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |