Changeset View
Changeset View
Standalone View
Standalone View
src/test/avalanche_tests.cpp
Show All 15 Lines | struct AvalancheTest { | ||||
static std::vector<CInv> getInvsForNextPoll(const AvalancheProcessor &p) { | static std::vector<CInv> getInvsForNextPoll(const AvalancheProcessor &p) { | ||||
return p.getInvsForNextPoll(); | return p.getInvsForNextPoll(); | ||||
} | } | ||||
static NodeId getSuitableNodeToQuery(AvalancheProcessor &p) { | static NodeId getSuitableNodeToQuery(AvalancheProcessor &p) { | ||||
return p.getSuitableNodeToQuery(); | return p.getSuitableNodeToQuery(); | ||||
} | } | ||||
static uint32_t getRound(const AvalancheProcessor &p) { return p.round; } | static uint64_t getRound(const AvalancheProcessor &p) { return p.round; } | ||||
}; | }; | ||||
BOOST_FIXTURE_TEST_SUITE(avalanche_tests, TestChain100Setup) | BOOST_FIXTURE_TEST_SUITE(avalanche_tests, TestChain100Setup) | ||||
#define REGISTER_VOTE_AND_CHECK(vr, vote, state, finalized, confidence) \ | #define REGISTER_VOTE_AND_CHECK(vr, vote, state, finalized, confidence) \ | ||||
vr.registerVote(vote); \ | vr.registerVote(vote); \ | ||||
BOOST_CHECK_EQUAL(vr.isAccepted(), state); \ | BOOST_CHECK_EQUAL(vr.isAccepted(), state); \ | ||||
BOOST_CHECK_EQUAL(vr.hasFinalized(), finalized); \ | BOOST_CHECK_EQUAL(vr.hasFinalized(), finalized); \ | ||||
▲ Show 20 Lines • Show All 468 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); | ||||
// Expire requests after some time. | |||||
p.setQueryTimeoutDuration(std::chrono::milliseconds(10)); | |||||
for (int i = 0; i < 10; i++) { | |||||
resp = {AvalancheTest::getRound(p), 0, {AvalancheVote(0, blockHash)}}; | |||||
AvalancheTest::runEventLoop(p); | |||||
// 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 | |||||
// this if that were to be the case. I never was able to trigger this | |||||
// myself, so it's probably good enough. | |||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(1)); | |||||
AvalancheTest::runEventLoop(p); | |||||
BOOST_CHECK(p.registerVotes(avanodeid, next(resp), updates)); | |||||
// Now try again but wait. | |||||
AvalancheTest::runEventLoop(p); | |||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(10)); | |||||
AvalancheTest::runEventLoop(p); | |||||
BOOST_CHECK(!p.registerVotes(avanodeid, next(resp), updates)); | |||||
} | |||||
CConnmanTest::ClearNodes(); | CConnmanTest::ClearNodes(); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(event_loop) { | BOOST_AUTO_TEST_CASE(event_loop) { | ||||
AvalancheProcessor p(g_connman.get()); | AvalancheProcessor p(g_connman.get()); | ||||
CScheduler s; | CScheduler s; | ||||
CBlock block = CreateAndProcessBlock({}, CScript()); | CBlock block = CreateAndProcessBlock({}, CScript()); | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |