Skip to content

Commit a5e756b

Browse files
author
MarcoFalke
committed
Merge #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/bitcoin#21602 (comment) ACKs for top commit: jonatack: Code review ACK fa40d6a jarolrod: ACK fa40d6a Tree-SHA512: 4967e006f3d2c4eb92f03c9086a6abe3190ad54755d251c30d20422c574bb1a154c06f3d5bcb0d4deaa3c4abfd3864d743b71d84897edd358e829bb42233ad12
2 parents 9712f75 + fa40d6a commit a5e756b

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
@@ -116,7 +116,6 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
116116
BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in disconnect
117117
}
118118
BOOST_CHECK(dummyNode1.fDisconnect == true);
119-
SetMockTime(0);
120119

121120
peerLogic->FinalizeNode(dummyNode1);
122121
}

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.00μ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
@@ -275,7 +275,11 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
275275

276276
BOOST_CHECK_NO_THROW(CallRPC(std::string("clearbanned")));
277277

278+
auto now = 10'000s;
279+
SetMockTime(now);
278280
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("setban 127.0.0.0/24 add 200")));
281+
SetMockTime(now += 2s);
282+
const int64_t time_remaining_expected{198};
279283
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned")));
280284
ar = r.get_array();
281285
o1 = ar[0].get_obj();
@@ -284,12 +288,10 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
284288
const int64_t ban_created{find_value(o1, "ban_created").get_int64()};
285289
const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()};
286290
const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()};
287-
const int64_t now{GetTime()};
288291
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
289-
BOOST_CHECK(banned_until > now);
290-
BOOST_CHECK(banned_until - now <= 200);
292+
BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count());
291293
BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
292-
BOOST_CHECK_EQUAL(time_remaining, banned_until - now);
294+
BOOST_CHECK_EQUAL(time_remaining, time_remaining_expected);
293295

294296
// must throw an exception because 127.0.0.1 is in already banned subnet range
295297
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
@@ -120,6 +120,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
120120

121121
BasicTestingSetup::~BasicTestingSetup()
122122
{
123+
SetMockTime(0s); // Reset mocktime for following tests
123124
LogInstance().DisconnectTestLogger();
124125
fs::remove_all(m_path_root);
125126
gArgs.ClearArgs();
@@ -303,7 +304,6 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
303304
TestChain100Setup::~TestChain100Setup()
304305
{
305306
gArgs.ForceSetArg("-segwitheight", "0");
306-
SetMockTime(0);
307307
}
308308

309309
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
@@ -295,8 +295,6 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
295295
BOOST_CHECK_EQUAL(found, expected);
296296
}
297297
}
298-
299-
SetMockTime(0);
300298
}
301299

302300
// Check that GetImmatureCredit() returns a newly calculated value instead of
@@ -377,9 +375,6 @@ BOOST_AUTO_TEST_CASE(ComputeTimeSmart)
377375
// If there are future entries, new transaction should use time of the
378376
// newest entry that is no more than 300 seconds ahead of the clock time.
379377
BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 5, 50, 600), 300);
380-
381-
// Reset mock time for other tests.
382-
SetMockTime(0);
383378
}
384379

385380
BOOST_AUTO_TEST_CASE(LoadReceiveRequests)

0 commit comments

Comments
 (0)