mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-15 16:33:52 +02:00
Merge bitcoin/bitcoin#34858: test: Use NodeClockContext in more tests
faad08e59ctest: Use NodeClockContext in more tests (MarcoFalke)fa8fe0941efuzz: Use NodeClockContext (MarcoFalke)fa9f434df8test: Allow time_point in boost checks (MarcoFalke) Pull request description: Currently mocktime is written to a global, which may leak between sub-tests (albeit some tests try to reset the mocktime on a best-effort basis). Also, when advancing it, one has to keep a counter variable around. Fix both issues by using the recently added `NodeClockContext`, which resets the mocktime once it goes out of scope. Also, it has a method to advance the mocktime by a delta. ACKs for top commit: achow101: ACKfaad08e59cseduless: Tested ACKfaad08e59cfrankomosh: Tested ACKfaad08e59c. Ran all relevant tests, all clean. Also verified that the default-constructor call sites in orphanage_tests and addrman_tests behave identically to the explicit `{Now<NodeSeconds>()}` form. ryanofsky: Code review ACKfaad08e59cbut had a question about dropping +1 in one test below. Tree-SHA512: bd56931970eed02bfcf3f3593ef64a61a8a1d8cc8adf190d6903b35df0fd7e6d865678c7d5bd23ce53d074cb2cf53a0a19212fdeb593b047dac5561859bc86b0
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/time.h>
|
||||
#include <uint256.h>
|
||||
#include <util/bitdeque.h>
|
||||
#include <util/byte_units.h>
|
||||
@@ -585,7 +586,7 @@ BOOST_AUTO_TEST_CASE(strprintf_numbers)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_mocktime)
|
||||
{
|
||||
SetMockTime(111s);
|
||||
NodeClockContext clock_ctx{111s};
|
||||
// Check that mock time does not change after a sleep
|
||||
for (const auto& num_sleep : {0ms, 1ms}) {
|
||||
UninterruptibleSleep(num_sleep);
|
||||
@@ -598,7 +599,6 @@ BOOST_AUTO_TEST_CASE(util_mocktime)
|
||||
BOOST_CHECK_EQUAL(111000, TicksSinceEpoch<std::chrono::milliseconds>(NodeClock::now()));
|
||||
BOOST_CHECK_EQUAL(111000000, GetTime<std::chrono::microseconds>().count());
|
||||
}
|
||||
SetMockTime(0s);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_ticksseconds)
|
||||
|
||||
Reference in New Issue
Block a user