Skip to content

Commit

Permalink
add real timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Dec 19, 2023
1 parent 68c8276 commit 0c998a7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions toxcore/mono_time_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <gtest/gtest.h>

#include <chrono>
#include <thread>

namespace {

TEST(MonoTime, UnixTimeIncreasesOverTime)
Expand Down Expand Up @@ -41,6 +44,24 @@ TEST(MonoTime, IsTimeout)
mono_time_free(mem, mono_time);
}

TEST(MonoTime, IsTimeoutReal)
{
const Memory *mem = system_memory();
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ASSERT_NE(mono_time, nullptr);

uint64_t const start = mono_time_get(mono_time);
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));

std::this_thread::sleep_for(std::chrono::milliseconds(100));
mono_time_update(mono_time);

// should still not have timed out (5sec) after sleeping ~100ms
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));

mono_time_free(mem, mono_time);
}

TEST(MonoTime, CustomTime)
{
const Memory *mem = system_memory();
Expand Down

0 comments on commit 0c998a7

Please sign in to comment.