blob: 90bc877bfcdd66e28d818998a3e365319868b8e8 [file] [log] [blame]
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02001#include "dbus_environment.hpp"
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +00002#include "helpers.hpp"
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02003#include "utils/detached_timer.hpp"
4
5#include <gmock/gmock.h>
6
7namespace utils
8{
9
10using namespace testing;
11using namespace std::chrono_literals;
12
13class TestDetachedTimer : public Test
14{
15 public:
16 uint32_t value = 0;
17};
18
19TEST_F(TestDetachedTimer, executesLambdaAfterTimeout)
20{
21 auto setPromise = DbusEnvironment::setPromise("timer");
22
23 makeDetachedTimer(DbusEnvironment::getIoc(), 100ms, [this, &setPromise] {
24 ++value;
25 setPromise();
26 });
27
Patrick Williams583ba442025-02-03 14:28:19 -050028 auto elapsed = DbusEnvironment::measureTime([] {
29 DbusEnvironment::waitForFuture("timer");
30 });
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +020031
32 EXPECT_THAT(elapsed, AllOf(Ge(100ms), Lt(200ms)));
33 EXPECT_THAT(value, Eq(1u));
34}
35
36} // namespace utils