-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
test_time.h
55 lines (41 loc) · 1.46 KB
/
test_time.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include "source/common/event/real_time_system.h"
#include "test/test_common/global.h"
#include "test/test_common/test_time_system.h"
namespace Envoy {
namespace Event {
class TestRealTimeSystem : public TestTimeSystem {
public:
// TestTimeSystem
void advanceTimeAsyncImpl(const Duration& duration) override;
void advanceTimeWaitImpl(const Duration& duration) override;
// Event::TimeSystem
Event::SchedulerPtr createScheduler(Scheduler& base_scheduler,
CallbackScheduler& cb_scheduler) override {
return real_time_system_.createScheduler(base_scheduler, cb_scheduler);
}
// TimeSource
SystemTime systemTime() override;
MonotonicTime monotonicTime() override;
private:
Event::RealTimeSystem real_time_system_;
};
class GlobalTimeSystem : public DelegatingTestTimeSystemBase<TestTimeSystem> {
public:
TestTimeSystem& timeSystem() override;
private:
Test::Global<SingletonTimeSystemHelper> singleton_;
};
} // namespace Event
// Instantiates real-time sources for testing purposes. In general, this is a
// bad idea, and tests should use simulated or mock time.
//
// TODO(#4160): change most references to this class to SimulatedTimeSystem.
class DangerousDeprecatedTestTime {
public:
DangerousDeprecatedTestTime();
Event::TestTimeSystem& timeSystem() { return time_system_.timeSystem(); }
private:
Event::DelegatingTestTimeSystem<Event::TestRealTimeSystem> time_system_;
};
} // namespace Envoy