10 #ifndef OCM_DAQ_TEST_PROGRESS_HPP
11 #define OCM_DAQ_TEST_PROGRESS_HPP
16 #include <boost/chrono.hpp>
18 #include <boost/asio/io_context.hpp>
19 #include <gtest/gtest.h>
25 template<
class Predicate>
27 timeout = std::chrono::seconds(3)) {
28 auto until = std::chrono::steady_clock::now() + timeout;
30 while(std::chrono::steady_clock::now() < until) {
37 FAIL() <<
"MakeTestProgressUntil timed out";
46 template <
class Future =
void>
48 using namespace std::chrono;
49 using namespace ::testing;
51 auto work = std::make_unique<boost::asio::io_context::work>(io_ctx);
60 }
catch (std::exception
const& e) {
61 FAIL() <<
"MakeTestProgress caught std::exception: " << e.what();
63 FAIL() <<
"MakeTestProgress caught unknown exception";
66 std::this_thread::yield();
67 if constexpr (!std::is_same_v<Future, void>) {
69 EXPECT_NO_THROW(fut->wait_for(boost::chrono::seconds(3)));
78 ASSERT_TRUE(fut->is_ready()) <<
"Future is not ready after 1s, aborting";
void MakeTestProgress(boost::asio::io_context &io_ctx, Future *fut=nullptr)
Test helper that progress the test by executing pending jobs and optionally wait for a future to be r...
void MakeTestProgressUntil(boost::asio::io_context &io_ctx, Predicate &&pred, std::chrono::milliseconds timeout=std::chrono::seconds(3))
Executes io_ctx::poll until pred returns true or it times out.