blob: a9dd6c04c6e3f69b06451bc6e472f8a821466a31 [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
28 auto elapsed = DbusEnvironment::measureTime(
29 [] { DbusEnvironment::waitForFuture("timer"); });
30
31 EXPECT_THAT(elapsed, AllOf(Ge(100ms), Lt(200ms)));
32 EXPECT_THAT(value, Eq(1u));
33}
34
35} // namespace utils