Changeset View
Changeset View
Standalone View
Standalone View
src/test/avalanche_tests.cpp
Show First 20 Lines • Show All 561 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(poll_and_response) { | ||||
// When a block is marked invalid, stop polling. | // When a block is marked invalid, stop polling. | ||||
pindex2->nStatus = pindex2->nStatus.withFailed(); | pindex2->nStatus = pindex2->nStatus.withFailed(); | ||||
resp = {AvalancheTest::getRound(p), 0, {AvalancheVote(0, blockHash)}}; | resp = {AvalancheTest::getRound(p), 0, {AvalancheVote(0, blockHash)}}; | ||||
AvalancheTest::runEventLoop(p); | AvalancheTest::runEventLoop(p); | ||||
BOOST_CHECK(p.registerVotes(avanodeid, resp, updates)); | BOOST_CHECK(p.registerVotes(avanodeid, resp, updates)); | ||||
BOOST_CHECK_EQUAL(updates.size(), 0); | BOOST_CHECK_EQUAL(updates.size(), 0); | ||||
BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); | ||||
CConnmanTest::ClearNodes(); | |||||
} | |||||
BOOST_AUTO_TEST_CASE(poll_inflight_timeout) { | |||||
AvalancheProcessor p(g_connman.get()); | |||||
std::vector<AvalancheBlockUpdate> updates; | |||||
CBlock block = CreateAndProcessBlock({}, CScript()); | |||||
const uint256 blockHash = block.GetHash(); | |||||
const CBlockIndex *pindex = mapBlockIndex[blockHash]; | |||||
// Add the block | |||||
BOOST_CHECK(p.addBlockToReconcile(pindex)); | |||||
// Create a node that supports avalanche. | |||||
const Config &config = GetConfig(); | |||||
auto avanode = ConnectNode(config, NODE_AVALANCHE, *peerLogic); | |||||
NodeId avanodeid = avanode->GetId(); | |||||
BOOST_CHECK(p.addPeer(avanodeid, 0)); | |||||
// Expire requests after some time. | // Expire requests after some time. | ||||
p.setQueryTimeoutDuration(std::chrono::milliseconds(10)); | p.setQueryTimeoutDuration(std::chrono::milliseconds(10)); | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
resp = {AvalancheTest::getRound(p), 0, {AvalancheVote(0, blockHash)}}; | AvalancheResponse resp = { | ||||
AvalancheTest::getRound(p), 0, {AvalancheVote(0, blockHash)}}; | |||||
AvalancheTest::runEventLoop(p); | AvalancheTest::runEventLoop(p); | ||||
// NB: This could wait longer than 1ms in some cases and make the | // NB: This could wait longer than 1ms in some cases and make the | ||||
// test flacky. We'll have to come up with a better solution to test | // test flacky. We'll have to come up with a better solution to test | ||||
// this if that were to be the case. I never was able to trigger this | // this if that were to be the case. I never was able to trigger this | ||||
// myself, so it's probably good enough. | // myself, so it's probably good enough. | ||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); | boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); | ||||
AvalancheTest::runEventLoop(p); | AvalancheTest::runEventLoop(p); | ||||
BOOST_CHECK(p.registerVotes(avanodeid, next(resp), updates)); | BOOST_CHECK(p.registerVotes(avanodeid, next(resp), updates)); | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |