Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show First 20 Lines • Show All 831 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(dont_poll_invalid_block) { | ||||
// When a block is marked invalid, stop polling. | // When a block is marked invalid, stop polling. | ||||
pindexB->nStatus = pindexB->nStatus.withFailed(); | pindexB->nStatus = pindexB->nStatus.withFailed(); | ||||
Response resp{getRound(), 0, {Vote(0, blockHashA)}}; | Response resp{getRound(), 0, {Vote(0, blockHashA)}}; | ||||
runEventLoop(); | runEventLoop(); | ||||
BOOST_CHECK(registerVotes(avanodes[0]->GetId(), resp, updates)); | BOOST_CHECK(registerVotes(avanodes[0]->GetId(), resp, updates)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 0); | BOOST_CHECK_EQUAL(updates.size(), 0); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(poll_inflight_timeout, *boost::unit_test::timeout(60)) { | BOOST_TEST_DECORATOR(*boost::unit_test::timeout(60)) | ||||
std::vector<BlockUpdate> updates; | BOOST_AUTO_TEST_CASE_TEMPLATE(poll_inflight_timeout, T, | ||||
voteItemTestingContexts) { | |||||
T context(this); | |||||
CBlock block = CreateAndProcessBlock({}, CScript()); | const auto item = context.buildVoteItem(); | ||||
const BlockHash blockHash = block.GetHash(); | const auto itemid = context.getVoteItemId(item); | ||||
const CBlockIndex *pindex; | |||||
{ | |||||
LOCK(cs_main); | |||||
pindex = LookupBlockIndex(blockHash); | |||||
} | |||||
// Add the block | // Add the item | ||||
BOOST_CHECK(m_processor->addBlockToReconcile(pindex)); | BOOST_CHECK(context.addToReconcile(item)); | ||||
// Create a node that supports avalanche. | // Create a node that supports avalanche. | ||||
auto avanode = ConnectNode(NODE_AVALANCHE); | auto avanode = ConnectNode(NODE_AVALANCHE); | ||||
NodeId avanodeid = avanode->GetId(); | NodeId avanodeid = avanode->GetId(); | ||||
BOOST_CHECK(addNode(avanodeid)); | BOOST_CHECK(addNode(avanodeid)); | ||||
// Expire requests after some time. | // Expire requests after some time. | ||||
auto queryTimeDuration = std::chrono::milliseconds(10); | auto queryTimeDuration = std::chrono::milliseconds(10); | ||||
m_processor->setQueryTimeoutDuration(queryTimeDuration); | m_processor->setQueryTimeoutDuration(queryTimeDuration); | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
Response resp = {getRound(), 0, {Vote(0, blockHash)}}; | Response resp = {getRound(), 0, {Vote(0, itemid)}}; | ||||
auto start = std::chrono::steady_clock::now(); | auto start = std::chrono::steady_clock::now(); | ||||
runEventLoop(); | runEventLoop(); | ||||
// We cannot guarantee that we'll wait for just 1ms, so we have to bail | // We cannot guarantee that we'll wait for just 1ms, so we have to bail | ||||
// if we aren't within the proper time range. | // if we aren't within the proper time range. | ||||
std::this_thread::sleep_for(std::chrono::milliseconds(1)); | std::this_thread::sleep_for(std::chrono::milliseconds(1)); | ||||
runEventLoop(); | runEventLoop(); | ||||
bool ret = registerVotes(avanodeid, next(resp), updates); | bool ret = context.registerVotes(avanodeid, next(resp)); | ||||
if (std::chrono::steady_clock::now() > start + queryTimeDuration) { | if (std::chrono::steady_clock::now() > start + queryTimeDuration) { | ||||
// We waited for too long, bail. Because we can't know for sure when | // We waited for too long, bail. Because we can't know for sure when | ||||
// previous steps ran, ret is not deterministic and we do not check | // previous steps ran, ret is not deterministic and we do not check | ||||
// it. | // it. | ||||
i--; | i--; | ||||
continue; | continue; | ||||
} | } | ||||
// We are within time bounds, so the vote should have worked. | // We are within time bounds, so the vote should have worked. | ||||
BOOST_CHECK(ret); | BOOST_CHECK(ret); | ||||
// Now try again but wait for expiration. | // Now try again but wait for expiration. | ||||
runEventLoop(); | runEventLoop(); | ||||
std::this_thread::sleep_for(queryTimeDuration); | std::this_thread::sleep_for(queryTimeDuration); | ||||
runEventLoop(); | runEventLoop(); | ||||
BOOST_CHECK(!registerVotes(avanodeid, next(resp), updates)); | BOOST_CHECK(!context.registerVotes(avanodeid, next(resp))); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(poll_inflight_count) { | BOOST_AUTO_TEST_CASE(poll_inflight_count) { | ||||
// Create enough nodes so that we run into the inflight request limit. | // Create enough nodes so that we run into the inflight request limit. | ||||
auto proof = GetProof(); | auto proof = GetProof(); | ||||
BOOST_CHECK(m_processor->withPeerManager( | BOOST_CHECK(m_processor->withPeerManager( | ||||
[&](avalanche::PeerManager &pm) { return pm.registerProof(proof); })); | [&](avalanche::PeerManager &pm) { return pm.registerProof(proof); })); | ||||
▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines |