From 0c998a75980d24e3147148f35b99ef3408fb25d0 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 18 Dec 2023 23:14:02 +0100 Subject: [PATCH] add real timeout test --- toxcore/mono_time_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/toxcore/mono_time_test.cc b/toxcore/mono_time_test.cc index 379b606c..cc667199 100644 --- a/toxcore/mono_time_test.cc +++ b/toxcore/mono_time_test.cc @@ -2,6 +2,9 @@ #include +#include +#include + namespace { TEST(MonoTime, UnixTimeIncreasesOverTime) @@ -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();