Skip to content

Commit 5a64dc0

Browse files
committed
refactor: addrman_evictionworks test
Test for collisions and duplicates directly with `Good()`. If an entry to tried is a duplicate, `Good()` will return false but `SelectTriedCollision()` will be empty (assuming there were no prior collisions). If there is a collision, `Good()` will retun false and `SelectTriedCollision()` will return a value.
1 parent e281fcc commit 5a64dc0

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/test/addrman_tests.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -901,19 +901,16 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
901901
for (unsigned int i = 1; i < 36; i++) {
902902
CService addr = ResolveService("250.1.1." + ToString(i));
903903
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
904-
addrman.Good(addr);
905904

906905
// No collision yet.
907-
BOOST_CHECK(addrman.size() == i);
908-
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
906+
BOOST_CHECK(addrman.Good(addr));
909907
}
910908

911909
// Collision between 36 and 19.
912910
CService addr = ResolveService("250.1.1.36");
913911
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
914-
addrman.Good(addr);
912+
BOOST_CHECK(!addrman.Good(addr));
915913

916-
BOOST_CHECK_EQUAL(addrman.size(), 36);
917914
auto info = addrman.SelectTriedCollision().first;
918915
BOOST_CHECK_EQUAL(info.ToString(), "250.1.1.19:0");
919916

@@ -924,17 +921,17 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
924921
addrman.ResolveCollisions();
925922
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
926923

927-
// If 36 was swapped for 19, then this should cause no collisions.
928-
BOOST_CHECK(!addrman.Add({CAddress(addr, NODE_NONE)}, source));
929-
addrman.Good(addr);
930-
924+
// If 36 was swapped for 19, then adding 36 to tried should fail because we
925+
// are attempting to add a duplicate.
926+
// We check this by verifying Good() returns false and also verifying that
927+
// we have no collisions.
928+
BOOST_CHECK(!addrman.Good(addr));
931929
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
932930

933-
// If we insert 19 it should collide with 36
931+
// 19 should fail as a collision (not a duplicate) if we now attempt to move
932+
// it to the tried table.
934933
CService addr19 = ResolveService("250.1.1.19");
935-
BOOST_CHECK(!addrman.Add({CAddress(addr19, NODE_NONE)}, source));
936-
addrman.Good(addr19);
937-
934+
BOOST_CHECK(!addrman.Good(addr19));
938935
BOOST_CHECK_EQUAL(addrman.SelectTriedCollision().first.ToString(), "250.1.1.36:0");
939936

940937
addrman.ResolveCollisions();

0 commit comments

Comments
 (0)