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