ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
testAsyncOpAbort.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_ocm_libdaq_test
4 * @copyright 2022 ESO - European Southern Observatory
5 *
6 * @brief Unit test for op::AbortAsync
7 */
8#include <daq/config.hpp>
9
10#include <gmock/gmock.h>
11#include <gtest/gtest.h>
12#include <log4cplus/logger.h>
13
14#include <daq/error.hpp>
15#include <daq/op/abort.hpp>
16#include <daq/op/initiate.hpp>
17
19#include "testAsyncOpBase.hpp"
20#include "utils.hpp"
21
22using namespace daq;
23using namespace ::testing;
24
25/**
26 * @ingroup daq_ocm_libdaq_test
27 */
29
31 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
32 auto reply_mock = std::make_shared<DaqReplyMock>();
33
34 EXPECT_CALL(*m_meta_rr_client, AbortDaq(_))
35 .WillOnce(Return(ByMove(reply_promise.get_future())));
36
37 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
38 auto reply_mock2 = std::make_shared<DaqReplyMock>();
39 EXPECT_CALL(*m_meta_rr_client2, AbortDaq(_))
40 .WillOnce(Return(ByMove(reply_promise2.get_future())));
41
42 boost::promise<std::string> prim_promise_1;
43 boost::promise<std::string> prim_promise_2;
44 EXPECT_CALL(*m_prim_rr_client, RecAbort())
45 .WillOnce(Return(ByMove(prim_promise_1.get_future())));
46 EXPECT_CALL(*m_prim_rr_client2, RecAbort())
47 .WillOnce(Return(ByMove(prim_promise_2.get_future())));
48
49 // Run
50 auto fut = op::InitiateOperation<op::AbortAsync>(m_executor, ErrorPolicy::Strict, MakeParams());
51
52 // "Send replies"
53 reply_promise.set_value(reply_mock);
54 reply_promise2.set_value(reply_mock);
55 prim_promise_1.set_value("OK"); // Unclear what RecIf is supposed to return here.
56 prim_promise_2.set_value("OK"); // Unclear what RecIf is supposed to return here.
57
58 // Execute handlers
59 MakeTestProgress(m_io_ctx, &fut);
60
61 ASSERT_TRUE(fut.is_ready());
62 ASSERT_FALSE(fut.has_exception()) << "Future has unexpected exception!";
63}
64
65TEST_F(TestAsyncOpAbort, AbortFailsWithStrictPolicyIfMetaSourceFails) {
66 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
67 auto reply_mock = std::make_shared<DaqReplyMock>();
68
69 EXPECT_CALL(*m_meta_rr_client, AbortDaq(_))
70 .WillOnce(Return(ByMove(reply_promise.get_future())));
71
72 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
73 auto reply_mock2 = std::make_shared<DaqReplyMock>();
74 EXPECT_CALL(*m_meta_rr_client2, AbortDaq(_))
75 .WillOnce(Return(ByMove(reply_promise2.get_future())));
76
77 boost::promise<std::string> prim_promise_1;
78 boost::promise<std::string> prim_promise_2;
79
80 EXPECT_CALL(*m_prim_rr_client, RecAbort())
81 .WillOnce(Return(ByMove(prim_promise_1.get_future())));
82 EXPECT_CALL(*m_prim_rr_client2, RecAbort())
83 .WillOnce(Return(ByMove(prim_promise_2.get_future())));
84
85 // Run
86 auto fut = op::InitiateOperation<op::AbortAsync>(m_executor, ErrorPolicy::Strict, MakeParams());
87
88 // "Send reply"
89 reply_promise.set_value(reply_mock);
90 reply_promise2.set_exception(metadaqif::DaqException(m_id, "message"));
91 prim_promise_1.set_value("OK"); // Unclear what RecIf is supposed to return here.
92 prim_promise_2.set_value("OK"); // Unclear what RecIf is supposed to return here.
93
94 // Execute handlers
95 MakeTestProgress(m_io_ctx, &fut);
96
97 ASSERT_TRUE(fut.is_ready());
98 EXPECT_THROW(fut.get(), daq::DaqSourceErrors);
99}
100
101TEST_F(TestAsyncOpAbort, AbortFailsWithStrictPolicyIfPrimSourceFails) {
102 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
103 auto reply_mock = std::make_shared<DaqReplyMock>();
104
105 EXPECT_CALL(*m_meta_rr_client, AbortDaq(_))
106 .WillOnce(Return(ByMove(reply_promise.get_future())));
107
108 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
109 auto reply_mock2 = std::make_shared<DaqReplyMock>();
110 EXPECT_CALL(*m_meta_rr_client2, AbortDaq(_))
111 .WillOnce(Return(ByMove(reply_promise2.get_future())));
112
113 boost::promise<std::string> prim_promise_1;
114 boost::promise<std::string> prim_promise_2;
115
116 EXPECT_CALL(*m_prim_rr_client, RecAbort())
117 .WillOnce(Return(ByMove(prim_promise_1.get_future())));
118 EXPECT_CALL(*m_prim_rr_client2, RecAbort())
119 .WillOnce(Return(ByMove(prim_promise_2.get_future())));
120
121 // Run
122 auto fut = op::InitiateOperation<op::AbortAsync>(m_executor, ErrorPolicy::Strict, MakeParams());
123
124 // "Send reply"
125 reply_promise.set_value(reply_mock);
126 reply_promise2.set_value(reply_mock);
127 prim_promise_1.set_value("OK"); // Unclear what RecIf is supposed to return here.
128 prim_promise_2.set_exception(metadaqif::DaqException(m_id, "message"));
129
130 // Execute handlers
131 MakeTestProgress(m_io_ctx, &fut);
132
133 ASSERT_TRUE(fut.is_ready());
134 EXPECT_THROW(fut.get(), daq::DaqSourceErrors);
135}
136
137TEST_F(TestAsyncOpAbort, AbortFailsWithTolerantPolicyIfMetaSourceFails) {
138 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
139 auto reply_mock = std::make_shared<DaqReplyMock>();
140
141 EXPECT_CALL(*m_meta_rr_client, AbortDaq(_))
142 .WillOnce(Return(ByMove(reply_promise.get_future())));
143
144 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
145 auto reply_mock2 = std::make_shared<DaqReplyMock>();
146 EXPECT_CALL(*m_meta_rr_client2, AbortDaq(_))
147 .WillOnce(Return(ByMove(reply_promise2.get_future())));
148
149 boost::promise<std::string> prim_promise_1;
150 boost::promise<std::string> prim_promise_2;
151 EXPECT_CALL(*m_prim_rr_client, RecAbort())
152 .WillOnce(Return(ByMove(prim_promise_1.get_future())));
153 EXPECT_CALL(*m_prim_rr_client2, RecAbort())
154 .WillOnce(Return(ByMove(prim_promise_2.get_future())));
155
156 // Run
157 auto fut =
158 op::InitiateOperation<op::AbortAsync>(m_executor, ErrorPolicy::Tolerant, MakeParams());
159
160 // "Send reply"
161 reply_promise.set_value(reply_mock);
162 reply_promise2.set_exception(metadaqif::DaqException(m_id, "message"));
163 prim_promise_1.set_value("OK"); // Unclear what RecIf is supposed to return here.
164 prim_promise_2.set_value("OK"); // Unclear what RecIf is supposed to return here.
165
166 // Execute handlers
167 MakeTestProgress(m_io_ctx, &fut);
168
169 ASSERT_TRUE(fut.is_ready());
170 EXPECT_FALSE(fut.has_exception());
171}
172
173TEST_F(TestAsyncOpAbort, AbortFailsWithTolerantPolicyIfPrimSourceFails) {
174 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise;
175 auto reply_mock = std::make_shared<DaqReplyMock>();
176
177 EXPECT_CALL(*m_meta_rr_client, AbortDaq(_))
178 .WillOnce(Return(ByMove(reply_promise.get_future())));
179
180 boost::promise<std::shared_ptr<metadaqif::DaqReply>> reply_promise2;
181 auto reply_mock2 = std::make_shared<DaqReplyMock>();
182 EXPECT_CALL(*m_meta_rr_client2, AbortDaq(_))
183 .WillOnce(Return(ByMove(reply_promise2.get_future())));
184
185 boost::promise<std::string> prim_promise_1;
186 boost::promise<std::string> prim_promise_2;
187 EXPECT_CALL(*m_prim_rr_client, RecAbort())
188 .WillOnce(Return(ByMove(prim_promise_1.get_future())));
189 EXPECT_CALL(*m_prim_rr_client2, RecAbort())
190 .WillOnce(Return(ByMove(prim_promise_2.get_future())));
191
192 // Run
193 auto fut =
194 op::InitiateOperation<op::AbortAsync>(m_executor, ErrorPolicy::Tolerant, MakeParams());
195
196 // "Send reply"
197 reply_promise.set_value(reply_mock);
198 reply_promise2.set_value(reply_mock);
199 prim_promise_1.set_value("OK");
200 prim_promise_2.set_exception(
201 std::runtime_error("some error")); // recif does not defin exception
202
203 // Execute handlers
204 MakeTestProgress(m_io_ctx, &fut);
205
206 ASSERT_TRUE(fut.is_ready());
207 EXPECT_FALSE(fut.has_exception());
208}
Contains declaration for the AbortAsync operation.
Exception thrown to carry reply errors.
Definition: error.hpp:85
Contains error related declarations for DAQ.
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...
Definition: utils.hpp:44
Base fixture for async operation tests.
Contains declarations for the helper functions to initiate operations.
Mockup of metadaqif classes.
TEST_F(TestAsyncOpAbort, Abort)
Contains declaration for async operations shared base class.
ASSERT_TRUE(std::holds_alternative< OlasReceiver >(spec.receivers[0]))
Defines shared test utilities.