blob: f84b4ed0dbb90b67c5b3ecaa37c3ea9ade093f29 [file] [log] [blame]
Alexander Hansen2cd25e62025-10-23 12:35:39 +02001#include "suite.hpp"
2
3#include <sdbusplus/timer.hpp>
4
5#include <chrono>
6
7#include <gtest/gtest.h>
8
9/** @brief Makes sure that timer is expired and the
10 * callback handler gets invoked post 2 seconds
11 */
12TEST_F(TimerTest, timerExpiresAfter2seconds)
13{
14 using namespace std::chrono;
15
16 auto time = duration_cast<microseconds>(seconds(2));
17 EXPECT_GE(timer.start(time), 0);
18
19 // Waiting 2 seconds is enough here since we have
20 // already spent some usec now
21 int count = 0;
22 while (count < 2 && !timer.isExpired())
23 {
24 // Returns -0- on timeout and positive number on dispatch
25 auto sleepTime = duration_cast<microseconds>(seconds(1));
26 if (!sd_event_run(events, sleepTime.count()))
27 {
28 count++;
29 }
30 }
31 EXPECT_EQ(true, timer.isExpired());
32 EXPECT_EQ(1, count);
33}