1 // This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
2 // the main distribution directory for license terms and copyright or visit
3 // https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
4 
5 #pragma once
6 
7 #include "caf/detail/core_export.hpp"
8 #include "caf/detail/simple_actor_clock.hpp"
9 
10 namespace caf::detail {
11 
12 class CAF_CORE_EXPORT test_actor_clock : public simple_actor_clock {
13 public:
14   time_point current_time;
15 
16   test_actor_clock();
17 
18   time_point now() const noexcept override;
19 
20   /// Returns whether the actor clock has at least one pending timeout.
has_pending_timeout() const21   bool has_pending_timeout() const {
22     return !schedule_.empty();
23   }
24 
25   /// Triggers the next pending timeout regardless of its timestamp. Sets
26   /// `current_time` to the time point of the triggered timeout unless
27   /// `current_time` is already set to a later time.
28   /// @returns Whether a timeout was triggered.
29   bool trigger_timeout();
30 
31   /// Triggers all pending timeouts regardless of their timestamp. Sets
32   /// `current_time` to the time point of the latest timeout unless
33   /// `current_time` is already set to a later time.
34   /// @returns The number of triggered timeouts.
35   size_t trigger_timeouts();
36 
37   /// Advances the time by `x` and dispatches timeouts and delayed messages.
38   /// @returns The number of triggered timeouts.
39   size_t advance_time(duration_type x);
40 };
41 
42 } // namespace caf::detail
43