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 <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]")
|
||||
{
|
||||
};
|
||||
|
||||
TEST_F(DecayingHashSetTest, TestDecayDeterministc)
|
||||
{
|
||||
static constexpr llarp_time_t timeout = 5;
|
||||
static constexpr llarp_time_t now = 1;
|
||||
static constexpr auto timeout = 5s;
|
||||
static constexpr auto now = 1s;
|
||||
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
||||
const llarp::RouterID zero;
|
||||
ASSERT_TRUE(zero.IsZero());
|
||||
ASSERT_FALSE(hashset.Contains(zero));
|
||||
ASSERT_TRUE(hashset.Insert(zero, now));
|
||||
ASSERT_TRUE(hashset.Contains(zero));
|
||||
hashset.Decay(now + 1);
|
||||
ASSERT_TRUE(hashset.Contains(zero));
|
||||
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));
|
||||
hashset.Decay(now + timeout);
|
||||
ASSERT_FALSE(hashset.Contains(zero));
|
||||
hashset.Decay(now + timeout + 1);
|
||||
ASSERT_FALSE(hashset.Contains(zero));
|
||||
REQUIRE(not hashset.Contains(zero));
|
||||
hashset.Decay(now + timeout + 1s);
|
||||
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;
|
||||
const llarp_time_t now = llarp::time_now_ms();
|
||||
static constexpr auto timeout = 5s;
|
||||
const llarp::Time_t now = llarp::time_now();
|
||||
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
||||
const llarp::RouterID zero;
|
||||
ASSERT_TRUE(zero.IsZero());
|
||||
ASSERT_FALSE(hashset.Contains(zero));
|
||||
ASSERT_TRUE(hashset.Insert(zero));
|
||||
ASSERT_TRUE(hashset.Contains(zero));
|
||||
hashset.Decay(now + 1);
|
||||
ASSERT_TRUE(hashset.Contains(zero));
|
||||
REQUIRE(zero.IsZero());
|
||||
REQUIRE(not hashset.Contains(zero));
|
||||
REQUIRE(hashset.Insert(zero));
|
||||
REQUIRE(hashset.Contains(zero));
|
||||
hashset.Decay(now + 1s);
|
||||
REQUIRE(hashset.Contains(zero));
|
||||
hashset.Decay(now + timeout);
|
||||
ASSERT_FALSE(hashset.Contains(zero));
|
||||
hashset.Decay(now + timeout + 1);
|
||||
ASSERT_FALSE(hashset.Contains(zero));
|
||||
REQUIRE(not hashset.Contains(zero));
|
||||
hashset.Decay(now + timeout + 1s);
|
||||
REQUIRE(not hashset.Contains(zero));
|
||||
}
|
||||
|
Loading…
Reference in New Issue