2019-12-30 20:52:10 +00:00
|
|
|
#include <util/decaying_hashset.hpp>
|
|
|
|
#include <router_id.hpp>
|
2020-02-24 15:26:46 +00:00
|
|
|
#include <catch2/catch.hpp>
|
2019-12-30 20:52:10 +00:00
|
|
|
|
2020-02-24 15:26:46 +00:00
|
|
|
TEST_CASE("DecayingHashSet test decay static time", "[decaying-hashset]")
|
2019-12-30 20:52:10 +00:00
|
|
|
{
|
2020-02-24 15:26:46 +00:00
|
|
|
static constexpr auto timeout = 5s;
|
2020-05-21 14:23:54 +00:00
|
|
|
static constexpr auto now = 1s;
|
2021-03-01 21:07:32 +00:00
|
|
|
llarp::util::DecayingHashSet<llarp::RouterID> hashset{timeout};
|
|
|
|
const llarp::RouterID zero{};
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(zero.IsZero());
|
|
|
|
REQUIRE(not hashset.Contains(zero));
|
|
|
|
REQUIRE(hashset.Insert(zero, now));
|
|
|
|
REQUIRE(hashset.Contains(zero));
|
|
|
|
hashset.Decay(now + 1s);
|
|
|
|
REQUIRE(hashset.Contains(zero));
|
2019-12-30 20:52:10 +00:00
|
|
|
hashset.Decay(now + timeout);
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(not hashset.Contains(zero));
|
|
|
|
hashset.Decay(now + timeout + 1s);
|
|
|
|
REQUIRE(not hashset.Contains(zero));
|
2019-12-30 20:52:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 21:07:32 +00:00
|
|
|
TEST_CASE("DecayingHashSet test decay dynamic time", "[decaying-hashset]")
|
2019-12-30 20:52:10 +00:00
|
|
|
{
|
2020-02-25 17:05:13 +00:00
|
|
|
static constexpr llarp_time_t timeout = 5s;
|
2021-03-04 20:47:09 +00:00
|
|
|
const auto now = llarp::time_now_ms();
|
2021-03-01 21:07:32 +00:00
|
|
|
llarp::util::DecayingHashSet<llarp::RouterID> hashset{timeout};
|
|
|
|
const llarp::RouterID zero{};
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(zero.IsZero());
|
|
|
|
REQUIRE(not hashset.Contains(zero));
|
2021-03-04 20:47:09 +00:00
|
|
|
REQUIRE(hashset.Insert(zero, now));
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(hashset.Contains(zero));
|
2021-03-04 20:47:09 +00:00
|
|
|
hashset.Decay(now + 1s);
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(hashset.Contains(zero));
|
2021-03-04 20:47:09 +00:00
|
|
|
hashset.Decay(now + timeout);
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(not hashset.Contains(zero));
|
2021-03-04 20:47:09 +00:00
|
|
|
hashset.Decay(now + timeout + 1s);
|
2020-02-24 15:26:46 +00:00
|
|
|
REQUIRE(not hashset.Contains(zero));
|
2019-12-30 20:52:10 +00:00
|
|
|
}
|