From d9862e8a6bbbcff62d55ff796d61fb17eaa99186 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Tue, 16 Nov 2021 16:47:58 +0100
Subject: [PATCH] fix tests

---
 .../api/cpp/unittests/test_producer_impl.cpp  |  2 +-
 .../cpp/unittests/test_producer_request.cpp   |  2 +-
 .../test_receiver_discovery_service.cpp       |  2 +-
 receiver/CMakeLists.txt                       | 11 +------
 .../test_receive_file_processor.cpp           | 30 +++---------------
 .../test_write_file_processor.cpp             | 31 +++----------------
 .../statistics/test_receiver_statistics.cpp   |  2 +-
 .../producer_receiver/CMakeLists.txt          |  6 +++-
 .../check_windows.bat                         |  9 ++++--
 9 files changed, 25 insertions(+), 70 deletions(-)

diff --git a/producer/api/cpp/unittests/test_producer_impl.cpp b/producer/api/cpp/unittests/test_producer_impl.cpp
index 8c0fda47f..c307cbf1d 100644
--- a/producer/api/cpp/unittests/test_producer_impl.cpp
+++ b/producer/api/cpp/unittests/test_producer_impl.cpp
@@ -606,7 +606,7 @@ TEST_F(ProducerImplTests, GetVersionInfoWithServer) {
         R"({"softwareVersion":"21.06.0, build 7a9294ad","clientSupported":"no", "clientProtocol":{"versionInfo":"v0.4"}})";
 
     EXPECT_CALL(*mock_http_client, Get_t(HasSubstr(expected_server_uri +
-                                                   "/asapo-discovery/v0.1/version?client=producer&protocol=v0.4"), _, _)).WillOnce(DoAll(
+                                                   "/asapo-discovery/v0.1/version?client=producer&protocol=v0.5"), _, _)).WillOnce(DoAll(
                                                            SetArgPointee<1>(asapo::HttpCode::OK),
                                                            SetArgPointee<2>(nullptr),
                                                            Return(result)));
diff --git a/producer/api/cpp/unittests/test_producer_request.cpp b/producer/api/cpp/unittests/test_producer_request.cpp
index 7a48b685d..ae0e560cf 100644
--- a/producer/api/cpp/unittests/test_producer_request.cpp
+++ b/producer/api/cpp/unittests/test_producer_request.cpp
@@ -40,7 +40,7 @@ TEST(ProducerRequest, Constructor) {
     uint64_t expected_file_size = 1337;
     uint64_t expected_meta_size = 137;
     std::string expected_meta = "meta";
-    std::string expected_api_version = "v0.4";
+    std::string expected_api_version = "v0.5";
     asapo::Opcode expected_op_code = asapo::kOpcodeTransferData;
 
     asapo::GenericRequestHeader header{expected_op_code, expected_file_id, expected_file_size,
diff --git a/producer/api/cpp/unittests/test_receiver_discovery_service.cpp b/producer/api/cpp/unittests/test_receiver_discovery_service.cpp
index c4103b8df..9b8be27b0 100644
--- a/producer/api/cpp/unittests/test_receiver_discovery_service.cpp
+++ b/producer/api/cpp/unittests/test_receiver_discovery_service.cpp
@@ -48,7 +48,7 @@ class ReceiversStatusTests : public Test {
     NiceMock<asapo::MockLogger> mock_logger;
     NiceMock<MockHttpClient>* mock_http_client;
 
-    std::string expected_endpoint{"endpoint/asapo-discovery/v0.1/asapo-receiver?protocol=v0.4"};
+    std::string expected_endpoint{"endpoint/asapo-discovery/v0.1/asapo-receiver?protocol=v0.5"};
     ReceiverDiscoveryService status{"endpoint", 20};
 
     void SetUp() override {
diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt
index af41e773a..836a04f9b 100644
--- a/receiver/CMakeLists.txt
+++ b/receiver/CMakeLists.txt
@@ -135,13 +135,4 @@ set(TEST_SOURCE_FILES_RDS
         unittests/receiver_data_server/request_handler/test_request_handler_factory.cpp
         unittests/receiver_data_server/request_handler/test_request_handler.cpp
         )
-gtest(${TARGET_NAME}_RDS "${TEST_SOURCE_FILES_RDS}" "${TEST_LIBRARIES}"
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/statistics/*.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/statistics/*.h
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/request_handler/*.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/request_handler/*.h
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/file_processors/*.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/file_processors/*.h
-        )
+gtest(${TARGET_NAME}_RDS "${TEST_SOURCE_FILES_RDS}" "${TEST_LIBRARIES}" nocov)
diff --git a/receiver/unittests/request_handler/file_processors/test_receive_file_processor.cpp b/receiver/unittests/request_handler/file_processors/test_receive_file_processor.cpp
index 4a129be53..0fe70c057 100644
--- a/receiver/unittests/request_handler/file_processors/test_receive_file_processor.cpp
+++ b/receiver/unittests/request_handler/file_processors/test_receive_file_processor.cpp
@@ -11,32 +11,8 @@
 
 #include "../../receiver_mocking.h"
 
-using ::testing::Test;
-using ::testing::Return;
-using ::testing::ReturnRef;
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::SetArgReferee;
-using ::testing::Gt;
-using ::testing::Eq;
-using ::testing::Ne;
-using ::testing::Mock;
-using ::testing::NiceMock;
-using ::testing::InSequence;
-using ::testing::SetArgPointee;
-using ::testing::AllOf;
-using ::testing::HasSubstr;
-
-
-using ::asapo::Error;
-using ::asapo::ErrorInterface;
-using ::asapo::FileDescriptor;
-using ::asapo::SocketDescriptor;
-using ::asapo::MockIO;
-using asapo::Request;
-using asapo::ReceiveFileProcessor;
-using ::asapo::GenericRequestHeader;
-using asapo::MockRequest;
+using namespace testing;
+using namespace asapo;
 
 namespace {
 
@@ -63,6 +39,7 @@ class ReceiveFileProcessorTests : public Test {
     uint64_t expected_file_size = 10;
     bool expected_overwrite = false;
     std::string expected_root_folder = "root_folder";
+    CustomRequestData expected_custom_data {kDefaultIngestMode, 0, 0};
     std::string expected_full_path =  expected_root_folder + asapo::kPathSeparator + expected_facility +
                                       asapo::kPathSeparator + "gpfs" +
                                       asapo::kPathSeparator + expected_beamline +
@@ -101,6 +78,7 @@ void ReceiveFileProcessorTests::MockRequestData() {
     EXPECT_CALL(*mock_request, GetSourceType()).Times(2)
     .WillRepeatedly(Return(expected_source_type));
 
+    EXPECT_CALL(*mock_request, GetCustomData_t()).WillRepeatedly(Return(expected_custom_data));
 
     EXPECT_CALL(*mock_request, GetFileName()).Times(2)
     .WillRepeatedly(Return(expected_file_name));
diff --git a/receiver/unittests/request_handler/file_processors/test_write_file_processor.cpp b/receiver/unittests/request_handler/file_processors/test_write_file_processor.cpp
index 02967f907..bead65417 100644
--- a/receiver/unittests/request_handler/file_processors/test_write_file_processor.cpp
+++ b/receiver/unittests/request_handler/file_processors/test_write_file_processor.cpp
@@ -11,32 +11,8 @@
 
 #include "../../receiver_mocking.h"
 
-using ::testing::Test;
-using ::testing::Return;
-using ::testing::ReturnRef;
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::SetArgReferee;
-using ::testing::Gt;
-using ::testing::Eq;
-using ::testing::Ne;
-using ::testing::Mock;
-using ::testing::NiceMock;
-using ::testing::InSequence;
-using ::testing::SetArgPointee;
-using ::testing::AllOf;
-using ::testing::HasSubstr;
-
-
-using ::asapo::Error;
-using ::asapo::ErrorInterface;
-using ::asapo::FileDescriptor;
-using ::asapo::SocketDescriptor;
-using ::asapo::MockIO;
-using asapo::Request;
-using asapo::WriteFileProcessor;
-using ::asapo::GenericRequestHeader;
-using asapo::MockRequest;
+using namespace testing;
+using namespace asapo;
 
 namespace {
 
@@ -62,6 +38,7 @@ class WriteFileProcessorTests : public Test {
     uint64_t expected_file_size = 10;
     bool expected_overwrite = false;
     std::string expected_root_folder = "root_folder";
+    CustomRequestData expected_custom_data {kDefaultIngestMode, 0, 0};
     std::string expected_full_path =  expected_root_folder + asapo::kPathSeparator + expected_facility +
                                       asapo::kPathSeparator + "gpfs" +
                                       asapo::kPathSeparator + expected_beamline +
@@ -107,6 +84,8 @@ void WriteFileProcessorTests::MockRequestData(int times) {
     EXPECT_CALL(*mock_request, GetSourceType()).Times(times * 2)
     .WillRepeatedly(Return(expected_source_type));
 
+    EXPECT_CALL(*mock_request, GetCustomData_t()).WillRepeatedly(Return(expected_custom_data));
+
 
     EXPECT_CALL(*mock_request, GetFileName()).Times(times * 2)
     .WillRepeatedly(Return(expected_file_name));
diff --git a/receiver/unittests/statistics/test_receiver_statistics.cpp b/receiver/unittests/statistics/test_receiver_statistics.cpp
index 318acac37..2956fb980 100644
--- a/receiver/unittests/statistics/test_receiver_statistics.cpp
+++ b/receiver/unittests/statistics/test_receiver_statistics.cpp
@@ -73,7 +73,7 @@ void ReceiverStatisticTests::TestTimer(const StatisticEntity& entity) {
 
     auto stat = ExtractStat();
 
-    ASSERT_THAT(stat.extra_entities[static_cast<size_t>(entity)].second, Ge(0.3));
+    ASSERT_THAT(stat.extra_entities[static_cast<size_t>(entity)].second, Gt(0));
     ASSERT_THAT(stat.extra_entities[static_cast<size_t>(entity)].second, Le(1.0));
 
 }
diff --git a/tests/automatic/producer_receiver/CMakeLists.txt b/tests/automatic/producer_receiver/CMakeLists.txt
index 028133361..aae8d4bf6 100644
--- a/tests/automatic/producer_receiver/CMakeLists.txt
+++ b/tests/automatic/producer_receiver/CMakeLists.txt
@@ -1,6 +1,10 @@
 add_subdirectory(transfer_single_file)
 add_subdirectory(transfer_single_file_bypass_buffer)
-add_subdirectory(transfer_single_file_write_to_raw)
+
+if (BUILD_PYTHON)
+    add_subdirectory(transfer_single_file_write_to_raw)
+endif()
+
 
 add_subdirectory(transfer_datasets)
 
diff --git a/tests/automatic/producer_receiver/transfer_single_file_write_to_raw/check_windows.bat b/tests/automatic/producer_receiver/transfer_single_file_write_to_raw/check_windows.bat
index cb28a5124..5b9f488c3 100644
--- a/tests/automatic/producer_receiver/transfer_single_file_write_to_raw/check_windows.bat
+++ b/tests/automatic/producer_receiver/transfer_single_file_write_to_raw/check_windows.bat
@@ -11,14 +11,16 @@ mkdir %receiver_folder_online%
 
 set PYTHONPATH=%2
 
+echo test > file1
+
 "%1" "%3" %data_source% %beamtime_id%  "127.0.0.1:8400" > out
 type out
 
 FOR /F "usebackq" %%A IN ('%receiver_folder%\raw\python\file1') DO set size=%%~zA
-if %size% NEQ 5 goto :error
+if %size% NEQ 7 goto :error
 
 FOR /F "usebackq" %%A IN ('%receiver_folder_online%\raw\python\file1') DO set size=%%~zA
-if %size% NEQ 5 goto :error
+if %size% NEQ 7 goto :error
 
 goto :clean
 
@@ -27,7 +29,8 @@ call :clean
 exit /b 1
 
 :clean
-rmdir /S /Q %receiver_root_folder% %receiver_folder_online%
+rmdir /S /Q %receiver_root_folder%
+rmdir /S /Q %receiver_folder_online%
 echo db.dropDatabase() | %mongo_exe% %beamtime_id%_python
 
 
-- 
GitLab