Skip to content

Commit e281fcc

Browse files
committed
refactor: addrman_noevict test
Check the response from `Good()` wherever it is called. Previously, the test was using `size()` (incorrect for checking tried) and `SelectTriedCollision()` to determine if a collision happened.
1 parent 8bdd924 commit e281fcc

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/test/addrman_tests.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -844,49 +844,45 @@ BOOST_AUTO_TEST_CASE(addrman_noevict)
844844
for (unsigned int i = 1; i < 36; i++) {
845845
CService addr = ResolveService("250.1.1." + ToString(i));
846846
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
847-
addrman.Good(addr);
848847

849848
// No collision yet.
850-
BOOST_CHECK(addrman.size() == i);
851-
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
849+
BOOST_CHECK(addrman.Good(addr));
852850
}
853851

854-
// Collision between 36 and 19.
852+
// Collision in tried table between 36 and 19.
855853
CService addr36 = ResolveService("250.1.1.36");
856854
BOOST_CHECK(addrman.Add({CAddress(addr36, NODE_NONE)}, source));
857-
addrman.Good(addr36);
858-
859-
BOOST_CHECK(addrman.size() == 36);
855+
BOOST_CHECK(!addrman.Good(addr36));
860856
BOOST_CHECK_EQUAL(addrman.SelectTriedCollision().first.ToString(), "250.1.1.19:0");
861857

862858
// 36 should be discarded and 19 not evicted.
859+
// This means we keep 19 in the tried table and
860+
// 36 stays in the new table.
863861
addrman.ResolveCollisions();
864862
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
865863

866864
// Lets create two collisions.
867865
for (unsigned int i = 37; i < 59; i++) {
868866
CService addr = ResolveService("250.1.1." + ToString(i));
869867
BOOST_CHECK(addrman.Add({CAddress(addr, NODE_NONE)}, source));
870-
addrman.Good(addr);
871-
872-
BOOST_CHECK(addrman.size() == i);
873-
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
868+
BOOST_CHECK(addrman.Good(addr));
874869
}
875870

876-
// Cause a collision.
871+
// Cause a collision in the tried table.
877872
CService addr59 = ResolveService("250.1.1.59");
878873
BOOST_CHECK(addrman.Add({CAddress(addr59, NODE_NONE)}, source));
879-
addrman.Good(addr59);
880-
BOOST_CHECK(addrman.size() == 59);
874+
BOOST_CHECK(!addrman.Good(addr59));
881875

882876
BOOST_CHECK_EQUAL(addrman.SelectTriedCollision().first.ToString(), "250.1.1.10:0");
883877

884-
// Cause a second collision.
878+
// Cause a second collision in the new table.
885879
BOOST_CHECK(!addrman.Add({CAddress(addr36, NODE_NONE)}, source));
886-
addrman.Good(addr36);
887-
BOOST_CHECK(addrman.size() == 59);
888880

881+
// 36 still cannot be moved from new to tried due to colliding with 19
882+
BOOST_CHECK(!addrman.Good(addr36));
889883
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() != "[::]:0");
884+
885+
// Resolve all collisions.
890886
addrman.ResolveCollisions();
891887
BOOST_CHECK(addrman.SelectTriedCollision().first.ToString() == "[::]:0");
892888
}

0 commit comments

Comments
 (0)