From c9fbda00f3373c211ff843f8c3b3942f71e63ea4 Mon Sep 17 00:00:00 2001 From: justinvforvendetta Date: Thu, 28 Sep 2023 11:04:08 -0400 Subject: [PATCH] swap boost sleep with std sleep in bench/test removes all remaining traces of boost sleep, replaces with std chrono/time.h --- src/bench/examples.cpp | 2 +- src/test/checkqueue_tests.cpp | 2 +- src/test/scheduler_tests.cpp | 15 ++------------- src/test/txindex_tests.cpp | 2 +- src/test/validation_block_tests.cpp | 2 +- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/bench/examples.cpp b/src/bench/examples.cpp index e8e33a3f..e1c6fa49 100644 --- a/src/bench/examples.cpp +++ b/src/bench/examples.cpp @@ -12,7 +12,7 @@ static void Sleep100ms(benchmark::State& state) { while (state.KeepRunning()) { - MilliSleep(100); + UninterruptibleSleep(std::chrono::milliseconds{100}); } } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 6dc88dd7..06f5c0f2 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -396,7 +396,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) CCheckQueueControl control(queue.get()); // While sleeping, no other thread should execute to this point auto observed = ++nThreads; - MilliSleep(10); + UninterruptibleSleep(std::chrono::milliseconds{10}); fails += observed != nThreads; }); } diff --git a/src/test/scheduler_tests.cpp b/src/test/scheduler_tests.cpp index 39b90cd8..267f216c 100644 --- a/src/test/scheduler_tests.cpp +++ b/src/test/scheduler_tests.cpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -27,18 +28,6 @@ static void microTask(CScheduler& s, boost::mutex& mutex, int& counter, int delt } } -static void MicroSleep(uint64_t n) -{ -#if defined(HAVE_WORKING_BOOST_SLEEP_FOR) - boost::this_thread::sleep_for(boost::chrono::microseconds(n)); -#elif defined(HAVE_WORKING_BOOST_SLEEP) - boost::this_thread::sleep(boost::posix_time::microseconds(n)); -#else - //should never get here - #error missing boost sleep implementation -#endif -} - BOOST_AUTO_TEST_CASE(manythreads) { // Stress test: hundreds of microsecond-scheduled tasks, @@ -85,7 +74,7 @@ BOOST_AUTO_TEST_CASE(manythreads) for (int i = 0; i < 5; i++) microThreads.create_thread(boost::bind(&CScheduler::serviceQueue, µTasks)); - MicroSleep(600); + UninterruptibleSleep(std::chrono::microseconds{600}); now = boost::chrono::system_clock::now(); // More threads and more tasks: diff --git a/src/test/txindex_tests.cpp b/src/test/txindex_tests.cpp index 914a27cd..f5272e35 100644 --- a/src/test/txindex_tests.cpp +++ b/src/test/txindex_tests.cpp @@ -36,7 +36,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup) int64_t time_start = GetTimeMillis(); while (!txindex.BlockUntilSyncedToCurrentChain()) { BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis()); - MilliSleep(100); + UninterruptibleSleep(std::chrono::milliseconds{100}); } // Check that txindex has all txs that were in the chain before it started. diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index 1b90c055..077364f9 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -170,7 +170,7 @@ void BuildChain(const uint256& root, int height, const unsigned int invalid_rate threads.join_all(); while (GetMainSignals().CallbacksPending() > 0) { - MilliSleep(100); + UninterruptibleSleep(std::chrono::milliseconds{100}); } UnregisterValidationInterface(&sub);