Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mock_time.cpp
Go to the documentation of this file.
1#include <fc/mock_time.hpp>
2#include <thread>
3
4namespace fc {
5
6bool mock_time_traits::mock_enabled_ = false;
7const boost::posix_time::ptime mock_time_traits::epoch_{ boost::gregorian::date( 1970, 1, 1 ) };
8std::atomic<int64_t> mock_time_traits::now_{};
9
11 return epoch_ + boost::posix_time::microseconds( now_.load() );
12}
13
15 fc::time_point now( fc::microseconds( (t - epoch_).total_microseconds() ) );
16 set_now( now );
17}
18
20 now_ = now.time_since_epoch().count();
21 if( !mock_enabled_ ) mock_enabled_ = true;
22
23 // After modifying the clock, we need to sleep the thread to give the io_service
24 // the opportunity to poll and notice the change in clock time.
25 // See to_posix_duration()
26 std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) );
27}
28
30 return fc::time_point( fc::microseconds( ( mock_time_traits::now() - epoch_ ).total_microseconds() ) );
31}
32
33} //namespace fc
static fc::time_point fc_now()
Definition mock_time.cpp:29
static time_type now() noexcept
Definition mock_time.cpp:10
static void set_now(time_type t)
Definition mock_time.cpp:14
source_traits::time_type time_type
Definition mock_time.hpp:12
namespace sysio::chain
Definition authority.cpp:3