mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge bitcoin/bitcoin#29872: test: Add missing Assert(mock_time_in >= 0s) to SetMockTime
fae0db555c12dca75fb09e5fa7bbabdf39b8c1df refactor: Use chrono type for g_mock_time (MarcoFalke)
fa382d3dd0592f3cbd6e1de791449f49e06dae86 test: Add missing Assert(mock_time_in >= 0s) to SetMockTime (MarcoFalke)
Pull request description:
Seems odd to have the assert in the *deprecated* function, but not in the other.
Fix this by adding it to the other, and by inlining the deprecated one.
Also, use chrono type for the global mocktime variable.
ACKs for top commit:
davidgumberg:
crACK fae0db555c
stickies-v:
ACK fae0db555c12dca75fb09e5fa7bbabdf39b8c1df
Tree-SHA512: 630c2917422ff2a7fa307114f95f22ad3c205429ffe36e67f0b2650733e40c876289c1aecebe882a9123d3106db7606bd6eff067ed6e2ecb95765984d3fe8612
This commit is contained in:
parent
a7daee71da
commit
23f25a94fa
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); }
|
void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); }
|
||||||
|
|
||||||
static std::atomic<int64_t> nMockTime(0); //!< For testing
|
static std::atomic<std::chrono::seconds> g_mock_time{}; //!< For testing
|
||||||
|
|
||||||
bool ChronoSanityCheck()
|
bool ChronoSanityCheck()
|
||||||
{
|
{
|
||||||
@ -69,7 +69,7 @@ bool ChronoSanityCheck()
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
T GetTime()
|
T GetTime()
|
||||||
{
|
{
|
||||||
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{
|
const auto ret{
|
||||||
mocktime.count() ?
|
mocktime.count() ?
|
||||||
mocktime :
|
mocktime :
|
||||||
@ -89,20 +89,16 @@ static T GetSystemTime()
|
|||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMockTime(int64_t nMockTimeIn)
|
void SetMockTime(int64_t nMockTimeIn) { SetMockTime(std::chrono::seconds{nMockTimeIn}); }
|
||||||
{
|
|
||||||
Assert(nMockTimeIn >= 0);
|
|
||||||
nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMockTime(std::chrono::seconds mock_time_in)
|
void SetMockTime(std::chrono::seconds mock_time_in)
|
||||||
{
|
{
|
||||||
nMockTime.store(mock_time_in.count(), std::memory_order_relaxed);
|
Assert(mock_time_in >= 0s);
|
||||||
|
g_mock_time.store(mock_time_in, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::seconds GetMockTime()
|
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 GetTimeMillis()
|
int64_t GetTimeMillis()
|
||||||
|
Loading…
Reference in New Issue
Block a user