8#include <gtest/gtest.h>
11#include <mal/MalException.hpp>
17using namespace ::testing;
18using namespace std::chrono;
35 s.rr_uri =
"zpb.rr://127.0.0.1/daq";
73 m_dpm_client->status_signal(m_dpm_status);
75 <<
"Expected new state from status update signal";
85 EXPECT_FALSE(m_status->HasError());
88 m_dpm_status.timestamp = Status::Clock::now();
93 m_dpm_status.timestamp = Status::Clock::now();
94 m_dpm_status.alerts.push_back(
MakeAlert(
"dpm",
"oops",
"Something went wrong"));
96 m_dpm_client->status_signal(m_dpm_status);
98 <<
"Expected new state from status update signal";
99 EXPECT_TRUE(m_controller->GetErrorFlag());
105 auto fut = m_controller->StartAsync();
107 EXPECT_THROW(fut.get(), std::runtime_error);
115 EXPECT_THROW(fut.get(), std::runtime_error);
121 EXPECT_THROW(m_controller->UpdateKeywords({}), std::runtime_error);
129 boost::promise<R> reply;
130 EXPECT_CALL(*m_dpm_client, ScheduleAsync(_, _)).WillOnce(InvokeWithoutArgs([&] {
131 return reply.get_future();
135 auto fut = m_controller->ScheduleMergeAsync();
141 EXPECT_TRUE(fut.is_ready());
142 auto result = fut.get();
148 ScheduleMergeAsyncSucceedsIfDpmSucceedsWithStatusSignalReceivedBeforeReply) {
153 boost::promise<R> reply;
154 EXPECT_CALL(*m_dpm_client, ScheduleAsync(_, _)).WillOnce(InvokeWithoutArgs([&] {
155 return reply.get_future();
159 auto fut = m_controller->ScheduleMergeAsync();
163 m_dpm_client->status_signal(m_dpm_status);
170 EXPECT_TRUE(fut.is_ready());
171 auto result = fut.get();
181 boost::promise<R> reply;
182 EXPECT_CALL(*m_dpm_client, ScheduleAsync(_, _)).WillOnce(InvokeWithoutArgs([&] {
183 return reply.get_future();
187 auto fut = m_controller->ScheduleMergeAsync();
190 reply.set_exception(std::runtime_error(
"some_error"));
193 EXPECT_TRUE(fut.is_ready());
194 EXPECT_THROW(fut.get(), std::exception);
196 EXPECT_TRUE(m_controller->GetStatus()->HasError());
204 boost::promise<R> reply;
205 EXPECT_CALL(*m_dpm_client, ScheduleAsync(_, _)).WillOnce(InvokeWithoutArgs([&] {
206 return reply.get_future();
210 auto fut = m_controller->ScheduleMergeAsync();
211 reply.set_exception(elt::mal::TimeoutException(
"TIMEOUT"));
213 EXPECT_TRUE(fut.is_ready());
216 EXPECT_THROW(fut.get(), elt::mal::TimeoutException);
218 EXPECT_FALSE(m_controller->GetStatus()->HasError())
219 <<
"Error flag should not be set for timeouts";
228 auto fut = m_controller->ScheduleMergeAsync();
229 EXPECT_TRUE(fut.is_ready());
232 EXPECT_THROW(fut.get(), std::runtime_error);
234 EXPECT_FALSE(m_controller->GetStatus()->HasError());
244 EXPECT_TRUE(fut.is_ready());
245 auto result = fut.get();
258 boost::promise<R> reply;
259 EXPECT_CALL(*m_dpm_client, AbortAsync(
"id"))
260 .WillOnce(InvokeWithoutArgs([&] {
return reply.get_future(); }));
271 EXPECT_TRUE(fut.is_ready());
272 auto result = fut.get();
284 boost::promise<R> reply;
285 EXPECT_CALL(*m_dpm_client, AbortAsync(
"id"))
286 .WillOnce(InvokeWithoutArgs([&] {
return reply.get_future(); }));
292 reply.set_exception(std::runtime_error(
"ERROR"));
297 EXPECT_TRUE(fut.is_ready());
298 EXPECT_THROW(fut.get(), std::runtime_error);
300 EXPECT_FALSE(m_controller->GetStatus()->HasError())
301 <<
"Failed to abort is not a condition for marking DAQ as error";
Stores data acquisition status and allows subscription to status changes.
Stores data acquisition status and allows subscription to status changes.
std::shared_ptr< ObservableStatus > m_status
boost::asio::io_context m_io_ctx
Status m_dpm_status
Fake status update sample from DPM.
std::shared_ptr< DpmClientMock > m_dpm_client
std::shared_ptr< DpmDaqController > m_controller
std::shared_ptr< ObservableEventLog > m_event_log
Fixture for daq::DaqController life cycle tests.
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...
TEST_F(TestDpmClient, StartMonitoringSendsRequestAndReceivesReply)
bool HasError(Status const &status) noexcept
@ Strict
Any error is considered fatal and may lead to the operation being aborted.
@ Tolerant
Errors that can be ignored with partial completion of a command will be tolerated and is reported as ...
State
Observable states of the data acquisition process.
@ NotScheduled
Before daq is acknowledged by dpm it remains in NotScheduled.
@ Scheduled
daq is acknowledged by dpm and is scheduled for merging (i.e.
@ Aborted
Data acquisition has been aborted by user.
@ Merging
DAQ is being merged.
Alert MakeAlert(std::string_view category, std::string key, std::string description)
Construct alert.
Contains declaration for for DaqController.
Structure carrying context needed to start a Data Acquisition and construct a Data Product Specificat...
std::vector< Source > meta_sources
DpParts results
Results from Data Acquisition (FITS files and keywords).
std::string id
DAQ identfier, possibly provided by user.
Non observable status object that keeps stores status of data acquisition.
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
ASSERT_TRUE(std::holds_alternative< OlasReceiver >(spec.receivers[0]))
Defines shared test utilities.