From fa382d3dd0592f3cbd6e1de791449f49e06dae86 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 15 Apr 2024 12:57:17 +0200 Subject: test: Add missing Assert(mock_time_in >= 0s) to SetMockTime Also, inline the deprecated alias to avoid having the two go out of sync again in the future. --- src/util/time.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/util') diff --git a/src/util/time.cpp b/src/util/time.cpp index 456662bd84..e46a127b14 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -29,14 +29,10 @@ NodeClock::time_point NodeClock::now() noexcept return time_point{ret}; }; -void SetMockTime(int64_t nMockTimeIn) -{ - Assert(nMockTimeIn >= 0); - nMockTime.store(nMockTimeIn, std::memory_order_relaxed); -} - +void SetMockTime(int64_t nMockTimeIn) { SetMockTime(std::chrono::seconds{nMockTimeIn}); } void SetMockTime(std::chrono::seconds mock_time_in) { + Assert(mock_time_in >= 0s); nMockTime.store(mock_time_in.count(), std::memory_order_relaxed); } -- cgit v1.2.3 From fae0db555c12dca75fb09e5fa7bbabdf39b8c1df Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 15 Apr 2024 13:21:03 +0200 Subject: refactor: Use chrono type for g_mock_time This avoids verbose casts in the lines where the symbol is used. --- src/util/time.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/util') diff --git a/src/util/time.cpp b/src/util/time.cpp index e46a127b14..f08eb5300a 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -16,11 +16,11 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); } -static std::atomic nMockTime(0); //!< For testing +static std::atomic g_mock_time{}; //!< For testing NodeClock::time_point NodeClock::now() noexcept { - const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)}; + const auto mocktime{g_mock_time.load(std::memory_order_relaxed)}; const auto ret{ mocktime.count() ? mocktime : @@ -33,12 +33,12 @@ void SetMockTime(int64_t nMockTimeIn) { SetMockTime(std::chrono::seconds{nMockTi void SetMockTime(std::chrono::seconds mock_time_in) { Assert(mock_time_in >= 0s); - nMockTime.store(mock_time_in.count(), std::memory_order_relaxed); + g_mock_time.store(mock_time_in, std::memory_order_relaxed); } std::chrono::seconds GetMockTime() { - return std::chrono::seconds(nMockTime.load(std::memory_order_relaxed)); + return g_mock_time.load(std::memory_order_relaxed); } int64_t GetTime() { return GetTime().count(); } -- cgit v1.2.3