mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
test: refactor: Use FakeNodeClock over manual/global SetMockTime
Using SetMockTime in tests is problematic, because it often requires verbose calls to `SetMockTime(GetTime<std::chrono::seconds>() + offset)`. Also, it requires manual `SetMockTime(0);` at the end. Fix both issues by using FakeNodeClock.
This commit is contained in:
@@ -805,7 +805,7 @@ BOOST_AUTO_TEST_CASE(http_server_socket_tests)
|
||||
{
|
||||
// Hard code the timestamp for the Date header in the HTTP response
|
||||
// Wed Dec 11 00:47:09 2024 UTC
|
||||
SetMockTime(1733878029);
|
||||
FakeNodeClock clock{1733878029s};
|
||||
|
||||
// Prepare a request handler that just stores received requests so we can examine them.
|
||||
// Mutex is required to prevent a race between this test's main thread and the server's I/O loop.
|
||||
|
||||
@@ -105,6 +105,7 @@ BOOST_AUTO_TEST_CASE(calculate_max_weight_percentiles)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache)
|
||||
{
|
||||
FakeNodeClock clock{};
|
||||
MemPoolFeeRateEstimatorCache cache;
|
||||
const uint256 tip_hash{uint256::ONE};
|
||||
const uint256 next_tip_hash{uint256{2}};
|
||||
@@ -122,10 +123,9 @@ BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache)
|
||||
BOOST_CHECK(cached->m_economical == economical);
|
||||
BOOST_CHECK(!cache.GetCachedEstimate(next_tip_hash));
|
||||
|
||||
SetMockTime(GetTime<std::chrono::seconds>() + CACHE_LIFE + std::chrono::seconds{1});
|
||||
clock += CACHE_LIFE + std::chrono::seconds{1};
|
||||
BOOST_CHECK(cache.IsStale());
|
||||
BOOST_CHECK(!cache.GetCachedEstimate(tip_hash));
|
||||
SetMockTime(0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
|
||||
|
||||
Reference in New Issue
Block a user