Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show First 20 Lines • Show All 880 Lines • ▼ Show 20 Lines | for (int i = 0; i < 10; i++) { | ||||
// 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(!context.registerVotes(avanodeid, next(resp))); | BOOST_CHECK(!context.registerVotes(avanodeid, next(resp))); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(poll_inflight_count) { | BOOST_AUTO_TEST_CASE_TEMPLATE(poll_inflight_count, T, voteItemTestingContexts) { | ||||
T context(this); | |||||
const uint32_t invType = context.invType; | |||||
// 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); })); | ||||
std::array<CNode *, AVALANCHE_MAX_INFLIGHT_POLL + 1> nodes; | std::array<CNode *, AVALANCHE_MAX_INFLIGHT_POLL + 1> nodes; | ||||
for (auto &n : nodes) { | for (auto &n : nodes) { | ||||
n = ConnectNode(NODE_AVALANCHE); | n = ConnectNode(NODE_AVALANCHE); | ||||
BOOST_CHECK(addNode(n->GetId(), proof->getId())); | BOOST_CHECK(addNode(n->GetId(), proof->getId())); | ||||
} | } | ||||
// Add a block to poll | // Add an item to poll | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | const auto item = context.buildVoteItem(); | ||||
const BlockHash blockHash = block.GetHash(); | const auto itemid = context.getVoteItemId(item); | ||||
const CBlockIndex *pindex; | BOOST_CHECK(context.addToReconcile(item)); | ||||
{ | |||||
LOCK(cs_main); | |||||
pindex = LookupBlockIndex(blockHash); | |||||
} | |||||
BOOST_CHECK(m_processor->addBlockToReconcile(pindex)); | |||||
// Ensure there are enough requests in flight. | // Ensure there are enough requests in flight. | ||||
std::map<NodeId, uint64_t> node_round_map; | std::map<NodeId, uint64_t> node_round_map; | ||||
for (int i = 0; i < AVALANCHE_MAX_INFLIGHT_POLL; i++) { | for (int i = 0; i < AVALANCHE_MAX_INFLIGHT_POLL; i++) { | ||||
NodeId nodeid = getSuitableNodeToQuery(); | NodeId nodeid = getSuitableNodeToQuery(); | ||||
BOOST_CHECK(node_round_map.find(nodeid) == node_round_map.end()); | BOOST_CHECK(node_round_map.find(nodeid) == node_round_map.end()); | ||||
node_round_map.insert(std::pair<NodeId, uint64_t>(nodeid, getRound())); | node_round_map.insert(std::pair<NodeId, uint64_t>(nodeid, getRound())); | ||||
auto invs = getInvsForNextPoll(); | auto invs = getInvsForNextPoll(); | ||||
BOOST_CHECK_EQUAL(invs.size(), 1); | BOOST_CHECK_EQUAL(invs.size(), 1); | ||||
BOOST_CHECK_EQUAL(invs[0].type, MSG_BLOCK); | BOOST_CHECK_EQUAL(invs[0].type, invType); | ||||
BOOST_CHECK(invs[0].hash == blockHash); | BOOST_CHECK(invs[0].hash == itemid); | ||||
runEventLoop(); | runEventLoop(); | ||||
} | } | ||||
// Now that we have enough in flight requests, we shouldn't poll. | // Now that we have enough in flight requests, we shouldn't poll. | ||||
auto suitablenodeid = getSuitableNodeToQuery(); | auto suitablenodeid = getSuitableNodeToQuery(); | ||||
BOOST_CHECK(suitablenodeid != NO_NODE); | BOOST_CHECK(suitablenodeid != NO_NODE); | ||||
auto invs = getInvsForNextPoll(); | auto invs = getInvsForNextPoll(); | ||||
BOOST_CHECK_EQUAL(invs.size(), 0); | BOOST_CHECK_EQUAL(invs.size(), 0); | ||||
runEventLoop(); | runEventLoop(); | ||||
BOOST_CHECK_EQUAL(getSuitableNodeToQuery(), suitablenodeid); | BOOST_CHECK_EQUAL(getSuitableNodeToQuery(), suitablenodeid); | ||||
std::vector<BlockUpdate> updates; | |||||
// Send one response, now we can poll again. | // Send one response, now we can poll again. | ||||
auto it = node_round_map.begin(); | auto it = node_round_map.begin(); | ||||
Response resp = {it->second, 0, {Vote(0, blockHash)}}; | Response resp = {it->second, 0, {Vote(0, itemid)}}; | ||||
BOOST_CHECK(registerVotes(it->first, resp, updates)); | BOOST_CHECK(context.registerVotes(it->first, resp)); | ||||
node_round_map.erase(it); | node_round_map.erase(it); | ||||
invs = getInvsForNextPoll(); | invs = getInvsForNextPoll(); | ||||
BOOST_CHECK_EQUAL(invs.size(), 1); | BOOST_CHECK_EQUAL(invs.size(), 1); | ||||
BOOST_CHECK_EQUAL(invs[0].type, MSG_BLOCK); | BOOST_CHECK_EQUAL(invs[0].type, invType); | ||||
BOOST_CHECK(invs[0].hash == blockHash); | BOOST_CHECK(invs[0].hash == itemid); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(quorum_diversity) { | BOOST_AUTO_TEST_CASE(quorum_diversity) { | ||||
std::vector<BlockUpdate> updates; | std::vector<BlockUpdate> updates; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
const BlockHash blockHash = block.GetHash(); | const BlockHash blockHash = block.GetHash(); | ||||
const CBlockIndex *pindex; | const CBlockIndex *pindex; | ||||
▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines |