Skip to content

Commit 21ad71c

Browse files
MarcoFalkeknst
authored andcommitted
Merge bitcoin#21676: test: Use mocktime to avoid intermittent failure in rpc_tests
fa40d6a test: Reset mocktime in the common setup (MarcoFalke) fa78590 test: Use mocktime to avoid intermittent failure (MarcoFalke) Pull request description: See bitcoin#21602 (comment) ACKs for top commit: jonatack: Code review ACK fa40d6a jarolrod: ACK fa40d6a Tree-SHA512: 4967e006f3d2c4eb92f03c9086a6abe3190ad54755d251c30d20422c574bb1a154c06f3d5bcb0d4deaa3c4abfd3864d743b71d84897edd358e829bb42233ad12
1 parent 76a41eb commit 21ad71c

File tree

6 files changed

+7
-16
lines changed

6 files changed

+7
-16
lines changed

src/test/denialofservice_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
113113
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in disconnect
114114
}
115115
BOOST_CHECK(dummyNode1.fDisconnect == true);
116-
SetMockTime(0);
117116

118117
peerLogic->FinalizeNode(dummyNode1);
119118
}

src/test/logging_tests.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
1414

1515
BOOST_AUTO_TEST_CASE(logging_timer)
1616
{
17-
1817
SetMockTime(1);
1918
auto sec_timer = BCLog::Timer<std::chrono::seconds>("tests", "end_msg");
2019
SetMockTime(2);
@@ -29,8 +28,6 @@ BOOST_AUTO_TEST_CASE(logging_timer)
2928
auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
3029
SetMockTime(2);
3130
BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000μs)");
32-
33-
SetMockTime(0);
3431
}
3532

3633
BOOST_AUTO_TEST_SUITE_END()

src/test/mempool_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,6 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
571571
SetMockTime(42 + 8*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4);
572572
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), 0);
573573
// ... unless it has gone all the way to 0 (after getting past 1000/2)
574-
575-
SetMockTime(0);
576574
}
577575

578576
inline CTransactionRef make_tx(std::vector<CAmount>&& output_values, std::vector<CTransactionRef>&& inputs=std::vector<CTransactionRef>(), std::vector<uint32_t>&& input_indices=std::vector<uint32_t>())

src/test/rpc_tests.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
323323

324324
BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned")));
325325

326+
auto now = 10'000s;
327+
SetMockTime(now);
326328
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("setban 127.0.0.0/24 add 200")));
329+
SetMockTime(now += 2s);
330+
const int64_t time_remaining_expected{198};
327331
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned")));
328332
ar = r.get_array();
329333
o1 = ar[0].get_obj();
@@ -332,12 +336,10 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
332336
const int64_t ban_created{find_value(o1, "ban_created").get_int64()};
333337
const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()};
334338
const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()};
335-
const int64_t now{GetTime()};
336339
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
337-
BOOST_CHECK(banned_until > now);
338-
BOOST_CHECK(banned_until - now <= 200);
340+
BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count());
339341
BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
340-
BOOST_CHECK_EQUAL(time_remaining, banned_until - now);
342+
BOOST_CHECK_EQUAL(time_remaining, time_remaining_expected);
341343

342344
// must throw an exception because 127.0.0.1 is in already banned subnet range
343345
BOOST_CHECK_THROW(r = CallRPC(std::string("setban 127.0.0.1 add")), std::runtime_error);

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
195195

196196
BasicTestingSetup::~BasicTestingSetup()
197197
{
198+
SetMockTime(0s); // Reset mocktime for following tests
198199
connman.reset();
199200
llmq::quorumSnapshotManager.reset();
200201
m_node.cpoolman.reset();
@@ -498,7 +499,6 @@ TestChainSetup::~TestChainSetup()
498499
g_txindex->Stop();
499500
SyncWithValidationInterfaceQueue();
500501
g_txindex.reset();
501-
SetMockTime(0);
502502
}
503503

504504
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const

src/wallet/test/wallet_tests.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
315315
BOOST_CHECK_EQUAL(found, expected);
316316
}
317317
}
318-
319-
SetMockTime(0);
320318
}
321319

322320
// Verify getaddressinfo RPC produces more or less expected results
@@ -473,9 +471,6 @@ BOOST_AUTO_TEST_CASE(ComputeTimeSmart)
473471
// If there are future entries, new transaction should use time of the
474472
// newest entry that is no more than 300 seconds ahead of the clock time.
475473
BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 5, 50, 600), 300);
476-
477-
// Reset mock time for other tests.
478-
SetMockTime(0);
479474
}
480475

481476
BOOST_AUTO_TEST_CASE(LoadReceiveRequests)

0 commit comments

Comments
 (0)