userver: userver/utils/mock_now.hpp Source File
Loading...
Searching...
No Matches
mock_now.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/mock_now.hpp
4/// @brief Mocking and getting mocked time values
5/// @ingroup userver_universal
6
7#include <chrono>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace utils::datetime {
12
13/// @cond
14std::chrono::system_clock::time_point MockNow() noexcept;
15
16std::chrono::steady_clock::time_point MockSteadyNow() noexcept;
17///@endcond
18
19/// Sets the mocked value for utils::datetime::Now() and
20/// utils::datetime::SteadyNow().
21///
22/// Thread safe.
23void MockNowSet(std::chrono::system_clock::time_point new_mocked_now);
24
25/// Adds duration to current mocked time point value
26///
27/// Thread safe.
28///
29/// @throws utils::InvariantError if IsMockNow() returns false.
30void MockSleep(std::chrono::milliseconds duration);
31
32/// Removes time point mocking for utils::datetime::Now() and
33/// utils::datetime::SteadyNow().
34void MockNowUnset() noexcept;
35
36/// Returns true if time point is mocked for utils::datetime::Now() and
37/// utils::datetime::SteadyNow().
38bool IsMockNow() noexcept;
39
40} // namespace utils::datetime
41
42USERVER_NAMESPACE_END