12 #include <log4cplus/loggingmacros.h>
17 #include "mock/mockWorkspace.hpp"
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
24 using namespace ::testing;
28 std::unique_ptr<RsyncAsyncProcessIf>
operator()(boost::asio::io_context&,
33 auto rsync = std::make_unique<MockRsyncAsyncProcess>();
37 procs.push_back(rsync.get());
43 std::vector<MockRsyncAsyncProcess*>
procs;
49 std::unique_ptr<AsyncProcessIf>
operator()(boost::asio::io_context&, std::vector<std::string>) {
50 auto rsync = std::make_unique<MockRsyncAsyncProcess>();
54 procs.push_back(rsync.get());
60 std::vector<MockAsyncProcess*>
procs;
110 std::filesystem::path sources_root =
"sources";
116 if (std::holds_alternative<DpSpec::SourceFitsFile>(s)) {
117 auto const& source = std::get<DpSpec::SourceFitsFile>(s);
122 auto ws = std::make_unique<daq::dpm::MockDaqWorkspace>();
126 EXPECT_CALL(*ws, LoadSpecification()).WillRepeatedly(Return(
m_dpspec));
127 EXPECT_CALL(*ws, GetSourcesPath()).WillRepeatedly(Return(std::filesystem::path(
"sources")));
128 EXPECT_CALL(*ws, GetSourceLookupPath())
129 .WillRepeatedly(Return(std::filesystem::path(
"sources.json")));
130 EXPECT_CALL(*ws, GetPath())
132 .WillRepeatedly(Return(std::filesystem::path(
"")));
150 template <
class Pred>
154 if (
m_io_ctx.poll_one() == 0 || p()) {
166 std::unique_ptr<DaqControllerImpl>
m_daq;
171 using namespace ::testing;
176 EXPECT_CALL(*m_ws_mock_ptr, StoreSourceLookup(_));
187 m_dpspec.target.source = std::nullopt;
188 m_dpspec.sources.clear();
202 ASSERT_TRUE(m_dpspec.target.source);
203 ASSERT_TRUE(m_dpspec.sources.size() == 1);
205 m_resources.net_receive.SetLimit(0);
208 EXPECT_EQ(m_resolver.GetMapping().size(), 2u)
209 <<
"Setup should have added target and one extra source";
210 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"sources/target.fits")))
212 .WillRepeatedly(Return(
false));
213 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"sources/source.fits")))
215 .WillRepeatedly(Return(
false));
221 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"sources/source.fits")))
222 .WillOnce(Return(
true));
223 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"sources/target.fits")))
224 .WillOnce(Return(
true));
228 for (
auto& proc : m_rsync_factory.procs) {
229 proc->promise.set_value(0);
239 ASSERT_TRUE(m_dpspec.target.source);
240 ASSERT_TRUE(m_dpspec.sources.size() == 1);
242 m_resources.net_receive.SetLimit(0);
245 EXPECT_EQ(m_resolver.GetMapping().size(), 2u)
246 <<
"Setup should have added target and one extra source";
247 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"sources/target.fits")))
248 .WillOnce(Return(
false));
249 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"sources/source.fits")))
250 .WillOnce(Return(
false));
257 EXPECT_CALL(*m_ws_mock_ptr,
264 for (
auto& proc : m_rsync_factory.procs) {
265 proc->promise.set_value(
error++);
271 EXPECT_TRUE(m_daq->IsStopped());
283 m_initial_status.error =
true;
287 EXPECT_CALL(*m_ws_mock_ptr, Exists(_)).WillRepeatedly(Return(
true));
303 EXPECT_CALL(*m_ws_mock_ptr, GetSpecificationPath())
304 .WillRepeatedly(Return(
"specification.json"));
305 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"TEST.ID.fits")))
306 .WillOnce(Return(
false));
312 ASSERT_EQ(m_proc_factory.procs.size(), 1u);
313 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"TEST.ID.fits")))
314 .WillRepeatedly(Return(
true));
317 EXPECT_CALL(*m_ws_mock_ptr,
321 HasSubstr(
"Writing keywords required resizing")))),
327 EXPECT_CALL(*m_ws_mock_ptr, MakeResultSymlink(std::filesystem::path(
"TEST.ID.fits")));
330 std::string message =
331 R
"({"content":{"id":"primary_hdu_resize","message":"Writing keywords required resizing of primary HDU: Add space for at least 73 keywords to avoid resize"},"timestamp":1650964356522093759,"type":"alert"})";
332 m_proc_factory.procs[0]->stdout(8, message);
335 m_proc_factory.procs[0]->stdout(8,
"This is invalid JSON");
338 m_proc_factory.procs[0]->promise.set_value(0);
353 m_initial_status.error =
true;
356 EXPECT_CALL(*m_ws_mock_ptr, Exists(std::filesystem::path(
"TEST.ID.fits")))
357 .WillRepeatedly(Return(
true));
365 ASSERT_EQ(m_proc_factory.procs.size(), 0u);