mirror of https://github.com/oxen-io/lokinet
make decaying hashset use llarp::Time_t and move unit tests to use catch2
parent
39cdc9e6dd
commit
f4520ac920
@ -1,43 +1,39 @@
|
|||||||
#include <util/decaying_hashset.hpp>
|
#include <util/decaying_hashset.hpp>
|
||||||
#include <router_id.hpp>
|
#include <router_id.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
struct DecayingHashSetTest : public ::testing::Test
|
TEST_CASE("DecayingHashSet test decay static time", "[decaying-hashset]")
|
||||||
{
|
{
|
||||||
};
|
static constexpr auto timeout = 5s;
|
||||||
|
static constexpr auto now = 1s;
|
||||||
TEST_F(DecayingHashSetTest, TestDecayDeterministc)
|
|
||||||
{
|
|
||||||
static constexpr llarp_time_t timeout = 5;
|
|
||||||
static constexpr llarp_time_t now = 1;
|
|
||||||
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
||||||
const llarp::RouterID zero;
|
const llarp::RouterID zero;
|
||||||
ASSERT_TRUE(zero.IsZero());
|
REQUIRE(zero.IsZero());
|
||||||
ASSERT_FALSE(hashset.Contains(zero));
|
REQUIRE(not hashset.Contains(zero));
|
||||||
ASSERT_TRUE(hashset.Insert(zero, now));
|
REQUIRE(hashset.Insert(zero, now));
|
||||||
ASSERT_TRUE(hashset.Contains(zero));
|
REQUIRE(hashset.Contains(zero));
|
||||||
hashset.Decay(now + 1);
|
hashset.Decay(now + 1s);
|
||||||
ASSERT_TRUE(hashset.Contains(zero));
|
REQUIRE(hashset.Contains(zero));
|
||||||
hashset.Decay(now + timeout);
|
hashset.Decay(now + timeout);
|
||||||
ASSERT_FALSE(hashset.Contains(zero));
|
REQUIRE(not hashset.Contains(zero));
|
||||||
hashset.Decay(now + timeout + 1);
|
hashset.Decay(now + timeout + 1s);
|
||||||
ASSERT_FALSE(hashset.Contains(zero));
|
REQUIRE(not hashset.Contains(zero));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DecayingHashSetTest, TestDecay)
|
TEST_CASE("DecayingHashSet tset decay dynamic time", "[decaying-hashset]")
|
||||||
{
|
{
|
||||||
static constexpr llarp_time_t timeout = 5;
|
static constexpr auto timeout = 5s;
|
||||||
const llarp_time_t now = llarp::time_now_ms();
|
const llarp::Time_t now = llarp::time_now();
|
||||||
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
||||||
const llarp::RouterID zero;
|
const llarp::RouterID zero;
|
||||||
ASSERT_TRUE(zero.IsZero());
|
REQUIRE(zero.IsZero());
|
||||||
ASSERT_FALSE(hashset.Contains(zero));
|
REQUIRE(not hashset.Contains(zero));
|
||||||
ASSERT_TRUE(hashset.Insert(zero));
|
REQUIRE(hashset.Insert(zero));
|
||||||
ASSERT_TRUE(hashset.Contains(zero));
|
REQUIRE(hashset.Contains(zero));
|
||||||
hashset.Decay(now + 1);
|
hashset.Decay(now + 1s);
|
||||||
ASSERT_TRUE(hashset.Contains(zero));
|
REQUIRE(hashset.Contains(zero));
|
||||||
hashset.Decay(now + timeout);
|
hashset.Decay(now + timeout);
|
||||||
ASSERT_FALSE(hashset.Contains(zero));
|
REQUIRE(not hashset.Contains(zero));
|
||||||
hashset.Decay(now + timeout + 1);
|
hashset.Decay(now + timeout + 1s);
|
||||||
ASSERT_FALSE(hashset.Contains(zero));
|
REQUIRE(not hashset.Contains(zero));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue