Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 1,459 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < 10; i++) { | ||||
// The flag will not trigger again until we fail to select nodes again | // The flag will not trigger again until we fail to select nodes again | ||||
BOOST_CHECK(!pm.shouldRequestMoreNodes()); | BOOST_CHECK(!pm.shouldRequestMoreNodes()); | ||||
} | } | ||||
// Make it possible to request a node again | // Make it possible to request a node again | ||||
BOOST_CHECK(pm.updateNextRequestTime(0, std::chrono::steady_clock::now())); | BOOST_CHECK(pm.updateNextRequestTime(0, std::chrono::steady_clock::now())); | ||||
BOOST_CHECK_NE(pm.selectNode(), NO_NODE); | BOOST_CHECK_NE(pm.selectNode(), NO_NODE); | ||||
BOOST_CHECK(!pm.shouldRequestMoreNodes()); | BOOST_CHECK(!pm.shouldRequestMoreNodes()); | ||||
// Add another proof with no node attached | |||||
auto proof2 = | |||||
buildRandomProof(chainman.ActiveChainstate(), MIN_VALID_PROOF_SCORE); | |||||
BOOST_CHECK(pm.registerProof(proof2)); | |||||
pm.cleanupDanglingProofs(ProofRef()); | |||||
BOOST_CHECK(!pm.shouldRequestMoreNodes()); | |||||
// After some time the proof will be considered dangling and more nodes will | |||||
// be requested. | |||||
SetMockTime(GetTime() + 15 * 60); | |||||
pm.cleanupDanglingProofs(ProofRef()); | |||||
BOOST_CHECK(pm.shouldRequestMoreNodes()); | |||||
for (size_t i = 0; i < 10; i++) { | |||||
// The flag will not trigger again until the condition is met again | |||||
BOOST_CHECK(!pm.shouldRequestMoreNodes()); | |||||
} | |||||
// Attach a node to that proof | |||||
BOOST_CHECK(!pm.addNode(11, proof2->getId())); | |||||
BOOST_CHECK(pm.registerProof(proof2)); | |||||
SetMockTime(GetTime() + 15 * 60); | |||||
pm.cleanupDanglingProofs(ProofRef()); | |||||
BOOST_CHECK(!pm.shouldRequestMoreNodes()); | |||||
// Disconnect the node, the proof is dangling again | |||||
BOOST_CHECK(pm.removeNode(11)); | |||||
pm.cleanupDanglingProofs(ProofRef()); | |||||
BOOST_CHECK(pm.shouldRequestMoreNodes()); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(score_ordering) { | BOOST_AUTO_TEST_CASE(score_ordering) { | ||||
ChainstateManager &chainman = *Assert(m_node.chainman); | ChainstateManager &chainman = *Assert(m_node.chainman); | ||||
avalanche::PeerManager pm(chainman); | avalanche::PeerManager pm(chainman); | ||||
std::vector<uint32_t> expectedScores(10); | std::vector<uint32_t> expectedScores(10); | ||||
// Expect the peers to be ordered by descending score | // Expect the peers to be ordered by descending score | ||||
▲ Show 20 Lines • Show All 521 Lines • Show Last 20 Lines |