File tree Expand file tree Collapse file tree 5 files changed +34
-4
lines changed Expand file tree Collapse file tree 5 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
15
15
script.cpp
16
16
setup_common.cpp
17
17
str.cpp
18
+ time.cpp
18
19
transaction_utils.cpp
19
20
txmempool.cpp
20
21
validation.cpp
Original file line number Diff line number Diff line change
1
+ // Copyright (c) The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include < test/util/time.h>
Original file line number Diff line number Diff line change
1
+ // Copyright (c) The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #ifndef BITCOIN_TEST_UTIL_TIME_H
6
+ #define BITCOIN_TEST_UTIL_TIME_H
7
+
8
+ #include < util/time.h>
9
+
10
+ struct ElapseSteady {
11
+ MockableSteadyClock::mock_time_point::duration t{MockableSteadyClock::INITIAL_MOCK_TIME};
12
+ ElapseSteady ()
13
+ {
14
+ (*this )(0s); // init
15
+ }
16
+ void operator ()(std::chrono::milliseconds d)
17
+ {
18
+ t += d;
19
+ MockableSteadyClock::SetMockTime (t);
20
+ }
21
+ };
22
+
23
+ #endif // BITCOIN_TEST_UTIL_TIME_H
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread
21
21
22
22
static std::atomic<std::chrono::seconds> g_mock_time{}; // !< For testing
23
23
std::atomic<bool > g_used_system_time{false };
24
- static std::atomic<std::chrono::milliseconds > g_mock_steady_time{}; // !< For testing
24
+ static std::atomic<MockableSteadyClock::mock_time_point::duration > g_mock_steady_time{}; // !< For testing
25
25
26
26
NodeClock::time_point NodeClock::now () noexcept
27
27
{
@@ -62,7 +62,7 @@ MockableSteadyClock::time_point MockableSteadyClock::now() noexcept
62
62
return time_point{ret};
63
63
};
64
64
65
- void MockableSteadyClock::SetMockTime (std::chrono::milliseconds mock_time_in)
65
+ void MockableSteadyClock::SetMockTime (mock_time_point::duration mock_time_in)
66
66
{
67
67
Assert (mock_time_in >= 0s);
68
68
g_mock_steady_time.store (mock_time_in, std::memory_order_relaxed);
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ using SystemClock = std::chrono::system_clock;
38
38
struct MockableSteadyClock : public std ::chrono::steady_clock {
39
39
using time_point = std::chrono::time_point<MockableSteadyClock>;
40
40
41
- static constexpr std::chrono::milliseconds INITIAL_MOCK_TIME{1 };
41
+ using mock_time_point = std::chrono::time_point<MockableSteadyClock, std::chrono::milliseconds>;
42
+ static constexpr mock_time_point::duration INITIAL_MOCK_TIME{1 };
42
43
43
44
/* * Return current system time or mocked time, if set */
44
45
static time_point now () noexcept ;
@@ -50,7 +51,7 @@ struct MockableSteadyClock : public std::chrono::steady_clock {
50
51
* for testing.
51
52
* To stop mocking, call ClearMockTime().
52
53
*/
53
- static void SetMockTime (std::chrono::milliseconds mock_time_in);
54
+ static void SetMockTime (mock_time_point::duration mock_time_in);
54
55
55
56
/* * Clear mock time, go back to system steady clock. */
56
57
static void ClearMockTime ();
You can’t perform that action at this time.
0 commit comments