Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/processor_tests.cpp
Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | CNode *ConnectNode(const Config &config, ServiceFlags nServices, | ||||
return node; | return node; | ||||
} | } | ||||
std::array<CNode *, 8> ConnectNodes(const Config &config, Processor &p, | std::array<CNode *, 8> ConnectNodes(const Config &config, Processor &p, | ||||
ServiceFlags nServices, | ServiceFlags nServices, | ||||
PeerLogicValidation &peerLogic, | PeerLogicValidation &peerLogic, | ||||
CConnmanTest *connman) { | CConnmanTest *connman) { | ||||
PeerManager &pm = AvalancheTest::getPeerManager(p); | PeerManager &pm = AvalancheTest::getPeerManager(p); | ||||
Proof proof(100); | Proof proof = Proof::makeRandom(100); | ||||
std::array<CNode *, 8> nodes; | std::array<CNode *, 8> nodes; | ||||
for (CNode *&n : nodes) { | for (CNode *&n : nodes) { | ||||
n = ConnectNode(config, nServices, peerLogic, connman); | n = ConnectNode(config, nServices, peerLogic, connman); | ||||
BOOST_CHECK(pm.addNode(n->GetId(), proof, CPubKey())); | BOOST_CHECK(pm.addNode(n->GetId(), proof, CPubKey())); | ||||
} | } | ||||
return nodes; | return nodes; | ||||
▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_and_response) { | ||||
// There is no node to query. | // There is no node to query. | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), NO_NODE); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), NO_NODE); | ||||
// Create a node that supports avalanche and one that doesn't. | // Create a node that supports avalanche and one that doesn't. | ||||
ConnectNode(config, NODE_NONE, *peerLogic, connman.get()); | ConnectNode(config, NODE_NONE, *peerLogic, connman.get()); | ||||
auto avanode = | auto avanode = | ||||
ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
NodeId avanodeid = avanode->GetId(); | NodeId avanodeid = avanode->GetId(); | ||||
BOOST_CHECK(p.addPeer(avanodeid, Proof(100), CPubKey())); | BOOST_CHECK(p.addPeer(avanodeid, Proof::makeRandom(100), CPubKey())); | ||||
// It returns the avalanche peer. | // It returns the avalanche peer. | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | ||||
// Register a block and check it is added to the list of elements to poll. | // Register a block and check it is added to the list of elements to poll. | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
auto invs = AvalancheTest::getInvsForNextPoll(p); | auto invs = AvalancheTest::getInvsForNextPoll(p); | ||||
BOOST_CHECK_EQUAL(invs.size(), 1); | BOOST_CHECK_EQUAL(invs.size(), 1); | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_inflight_timeout, *boost::unit_test::timeout(60)) { | ||||
// Add the block | // Add the block | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
// Create a node that supports avalanche. | // Create a node that supports avalanche. | ||||
auto avanode = | auto avanode = | ||||
ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
NodeId avanodeid = avanode->GetId(); | NodeId avanodeid = avanode->GetId(); | ||||
BOOST_CHECK(p.addPeer(avanodeid, Proof(100), CPubKey())); | BOOST_CHECK(p.addPeer(avanodeid, Proof::makeRandom(100), CPubKey())); | ||||
// Expire requests after some time. | // Expire requests after some time. | ||||
auto queryTimeDuration = std::chrono::milliseconds(10); | auto queryTimeDuration = std::chrono::milliseconds(10); | ||||
p.setQueryTimeoutDuration(queryTimeDuration); | p.setQueryTimeoutDuration(queryTimeDuration); | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
Response resp = {AvalancheTest::getRound(p), 0, {Vote(0, blockHash)}}; | Response resp = {AvalancheTest::getRound(p), 0, {Vote(0, blockHash)}}; | ||||
auto start = std::chrono::steady_clock::now(); | auto start = std::chrono::steady_clock::now(); | ||||
Show All 31 Lines | BOOST_AUTO_TEST_CASE(poll_inflight_count) { | ||||
auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337); | ||||
auto peerLogic = std::make_unique<PeerLogicValidation>( | auto peerLogic = std::make_unique<PeerLogicValidation>( | ||||
connman.get(), nullptr, *m_node.scheduler, false); | connman.get(), nullptr, *m_node.scheduler, false); | ||||
Processor p(connman.get()); | Processor p(connman.get()); | ||||
// Create enough nodes so that we run into the inflight request limit. | // Create enough nodes so that we run into the inflight request limit. | ||||
PeerManager &pm = AvalancheTest::getPeerManager(p); | PeerManager &pm = AvalancheTest::getPeerManager(p); | ||||
Proof proof(100); | Proof proof = Proof::makeRandom(100); | ||||
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(config, NODE_AVALANCHE, *peerLogic, connman.get()); | n = ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
BOOST_CHECK(pm.addNode(n->GetId(), proof, CPubKey())); | BOOST_CHECK(pm.addNode(n->GetId(), proof, CPubKey())); | ||||
} | } | ||||
// Add a block to poll | // Add a block to poll | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(event_loop) { | ||||
// Start the scheduler thread. | // Start the scheduler thread. | ||||
std::thread schedulerThread(std::bind(&CScheduler::serviceQueue, &s)); | std::thread schedulerThread(std::bind(&CScheduler::serviceQueue, &s)); | ||||
// Create a node that supports avalanche. | // Create a node that supports avalanche. | ||||
auto avanode = | auto avanode = | ||||
ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); | ||||
NodeId nodeid = avanode->GetId(); | NodeId nodeid = avanode->GetId(); | ||||
BOOST_CHECK(p.addPeer(nodeid, Proof(100), CPubKey())); | BOOST_CHECK(p.addPeer(nodeid, Proof::makeRandom(100), CPubKey())); | ||||
// There is no query in flight at the moment. | // There is no query in flight at the moment. | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), nodeid); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), nodeid); | ||||
// Add a new block. Check it is added to the polls. | // Add a new block. Check it is added to the polls. | ||||
uint64_t queryRound = AvalancheTest::getRound(p); | uint64_t queryRound = AvalancheTest::getRound(p); | ||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | BOOST_CHECK(p.addBlockToReconcile(pindex)); | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |