diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 282f5ea5bf9..8281921dced 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -893,6 +893,20 @@ BOOST_AUTO_TEST_CASE(node_eviction_test) }, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, random_context)); + // An eviction is expected given >= 29 random eviction candidates. The eviction logic protects at most + // four peers by net group, eight by lowest ping time, four by last time of novel tx, up to eight non-tx-relay + // peers by last novel block time, and four more peers by last novel block time. + if (number_of_nodes >= 29) { + BOOST_CHECK(SelectNodeToEvict(GetRandomNodeEvictionCandidates(number_of_nodes, random_context))); + } + + // No eviction is expected given <= 20 random eviction candidates. The eviction logic protects at least + // four peers by net group, eight by lowest ping time, four by last time of novel tx and four peers by last + // novel block time. + if (number_of_nodes <= 20) { + BOOST_CHECK(!SelectNodeToEvict(GetRandomNodeEvictionCandidates(number_of_nodes, random_context))); + } + // Cases left to test: // * "Protect the half of the remaining nodes which have been connected the longest. [...]" // * "Pick out up to 1/4 peers that are localhost, sorted by longest uptime. [...]"