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