8#ifndef OCM_DAQ_TEST_UTILS_HPP_
9#define OCM_DAQ_TEST_UTILS_HPP_
14#include <boost/asio/io_context.hpp>
15#include <boost/asio/post.hpp>
16#include <gtest/gtest.h>
21template <
class Predicate>
24 std::chrono::milliseconds timeout = std::chrono::seconds(3)) {
25 auto until = std::chrono::steady_clock::now() + timeout;
27 while (std::chrono::steady_clock::now() < until) {
34 FAIL() <<
"MakeTestProgressUntil timed out";
43template <
class Future =
void>
45 using namespace std::chrono;
46 using namespace ::testing;
48 auto work = std::make_unique<boost::asio::io_context::work>(io_ctx);
57 }
catch (std::exception
const& e) {
58 FAIL() <<
"MakeTestProgress caught std::exception: " << e.what();
60 FAIL() <<
"MakeTestProgress caught unknown exception";
63 std::this_thread::yield();
64 if constexpr (!std::is_same_v<Future, void>) {
66 EXPECT_NO_THROW(fut->wait_for(boost::chrono::seconds(3)));
68 boost::asio::post(io_ctx, [&] {
77 ASSERT_TRUE(fut->is_ready()) <<
"Future is not ready after 1s, aborting";
81 boost::asio::post(io_ctx, [&] { work.reset(); });
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...
ASSERT_TRUE(std::holds_alternative< OlasReceiver >(spec.receivers[0]))
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.