blob: 47a4fa69c9c4fa7648fd6d072ff4561c0f9e4cfc [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 value is changed in between
10 * and that the new timer expires
11 */
12TEST_F(TimerTest, updateTimerAndExpectExpire)
13{
14 using namespace std::chrono;
15
16 auto time = duration_cast<microseconds>(seconds(2));
17 EXPECT_GE(timer.start(time), 0);
18
19 // Now sleep for a second and then set the new timeout value
20 sleep(1);
21
22 // New timeout is 3 seconds from THIS point.
23 time = duration_cast<microseconds>(seconds(3));
24 EXPECT_GE(timer.start(time), 0);
25
26 // Wait 3 seconds and see that timer is expired
27 int count = 0;
28 while (count < 3 && !timer.isExpired())
29 {
30 // Returns -0- on timeout
31 auto sleepTime = duration_cast<microseconds>(seconds(1));
32 if (!sd_event_run(events, sleepTime.count()))
33 {
34 count++;
35 }
36 }
37 EXPECT_EQ(true, timer.isExpired());
38 EXPECT_EQ(2, count);
39}