From 2c593cb5b8a49ef88d3e20997b49b8b2b0cd0f20 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Wed, 30 May 2018 13:30:21 +0200 Subject: [PATCH] add timeout to example --- CMakeLists.txt | 1 + CMakeModules/prepare_asapo.cmake | 6 +++++- common/cpp/include/preprocessor/definitions.h | 2 +- .../cpp/unittests/json_parser/test_json_parser.cpp | 4 ++-- .../producer/dummy-data-producer/check_windows.bat | 2 +- .../dummy-data-producer/dummy_data_producer.cpp | 11 ++++++++++- .../automatic/full_chain/simple_chain/check_linux.sh | 2 +- .../full_chain/simple_chain/check_windows.bat | 8 ++++---- .../check_monitoring/check_linux.sh | 2 +- .../transfer_single_file/check_linux.sh | 2 +- .../transfer_single_file/check_windows.bat | 2 +- .../{receiver.json.tpl => receiver.json.tpl.lin} | 2 +- tests/automatic/settings/receiver.json.tpl.win | 12 ++++++++++++ 13 files changed, 41 insertions(+), 15 deletions(-) rename tests/automatic/settings/{receiver.json.tpl => receiver.json.tpl.lin} (86%) create mode 100644 tests/automatic/settings/receiver.json.tpl.win diff --git a/CMakeLists.txt b/CMakeLists.txt index 58b498aa7..2285e204f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(ASAPO) set(CMAKE_CXX_STANDARD 11) IF(WIN32) set(CMAKE_CXX_FLAGS_DEBUG "/MTd") + add_definitions(-DWIN32) ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "GNU") SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/CMakeModules/prepare_asapo.cmake b/CMakeModules/prepare_asapo.cmake index d80e80166..53580a80b 100644 --- a/CMakeModules/prepare_asapo.cmake +++ b/CMakeModules/prepare_asapo.cmake @@ -4,10 +4,14 @@ function(prepare_asapo) get_target_property(DISCOVERY_FULLPATH asapo-discovery EXENAME) get_target_property(BROKER_FULLPATH asapo-broker EXENAME) set(WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}) + if (WIN32) + configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver.json.tpl.win receiver.json.tpl COPYONLY) + else() + configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver.json.tpl.lin receiver.json.tpl COPYONLY) + endif() configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver.nmd.in receiver.nmd @ONLY) configure_file(${CMAKE_SOURCE_DIR}/config/nomad/discovery.nmd.in discovery.nmd @ONLY) configure_file(${CMAKE_SOURCE_DIR}/config/nomad/broker.nmd.in broker.nmd @ONLY) - configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver.json.tpl receiver.json.tpl COPYONLY) configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/discovery_settings.json.tpl discovery.json.tpl COPYONLY) configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/broker_settings.json.tpl broker.json.tpl COPYONLY) endfunction() diff --git a/common/cpp/include/preprocessor/definitions.h b/common/cpp/include/preprocessor/definitions.h index 0e1571e4b..385ffd372 100644 --- a/common/cpp/include/preprocessor/definitions.h +++ b/common/cpp/include/preprocessor/definitions.h @@ -9,7 +9,7 @@ namespace asapo { const char kPathSeparator = -#ifdef _WIN32 +#ifdef WIN32 '\\'; #else '/'; diff --git a/common/cpp/unittests/json_parser/test_json_parser.cpp b/common/cpp/unittests/json_parser/test_json_parser.cpp index e884cb43c..863e56516 100644 --- a/common/cpp/unittests/json_parser/test_json_parser.cpp +++ b/common/cpp/unittests/json_parser/test_json_parser.cpp @@ -30,7 +30,7 @@ using asapo::IO; namespace { TEST(ParseString, SimpleConvertToJson) { - std::string json = R"({"_id":2,"foo":"foo","bar":1,"flag":true})"; + std::string json = R"({"_id":2,"foo":"foo:\\1","bar":1,"flag":true})"; JsonStringParser parser{json}; @@ -49,7 +49,7 @@ TEST(ParseString, SimpleConvertToJson) { ASSERT_THAT(id, Eq(2)); - ASSERT_THAT(foo, Eq("foo")); + ASSERT_THAT(foo, Eq("foo:\\1")); ASSERT_THAT(bar, Eq(1)); ASSERT_THAT(flag, true); diff --git a/examples/producer/dummy-data-producer/check_windows.bat b/examples/producer/dummy-data-producer/check_windows.bat index 95652e449..86ee30f77 100644 --- a/examples/producer/dummy-data-producer/check_windows.bat +++ b/examples/producer/dummy-data-producer/check_windows.bat @@ -1,4 +1,4 @@ -"%1" 0.0.0.0 1 1 2>&1 | findstr "not valid" || goto :error +"%1" 0.0.0.0 1 1 1 1 2>&1 | findstr "not successfully" || goto :error goto :clean :error diff --git a/examples/producer/dummy-data-producer/dummy_data_producer.cpp b/examples/producer/dummy-data-producer/dummy_data_producer.cpp index 976a049ea..3917685a1 100644 --- a/examples/producer/dummy-data-producer/dummy_data_producer.cpp +++ b/examples/producer/dummy-data-producer/dummy_data_producer.cpp @@ -83,7 +83,7 @@ int main (int argc, char* argv[]) { producer = asapo::Producer::Create(receiver_address, nthreads, asapo::RequestHandlerType::kFilesystem, &err); } producer->EnableLocalLog(true); - producer->SetLogLevel(asapo::LogLevel::Info); + producer->SetLogLevel(asapo::LogLevel::Debug); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); @@ -101,6 +101,9 @@ int main (int argc, char* argv[]) { return EXIT_FAILURE; } + uint64_t elapsed_ms = 0; + uint64_t timeout_sec = 30; + while (true) { mutex.lock(); if (nfiles <= 0) { @@ -108,6 +111,12 @@ int main (int argc, char* argv[]) { break; } mutex.unlock(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + elapsed_ms += 100; + if (elapsed_ms > timeout_sec * 1000) { + std::cerr << "Exit on timeout " << std::endl; + return EXIT_FAILURE; + } } high_resolution_clock::time_point t2 = high_resolution_clock::now(); diff --git a/tests/automatic/full_chain/simple_chain/check_linux.sh b/tests/automatic/full_chain/simple_chain/check_linux.sh index caccc3586..f384a4b70 100644 --- a/tests/automatic/full_chain/simple_chain/check_linux.sh +++ b/tests/automatic/full_chain/simple_chain/check_linux.sh @@ -8,7 +8,7 @@ broker_database_name=test_run monitor_database_name=db_test broker_address=127.0.0.1:5005 -receiver_folder=/tmp/asapo/recevier/files +receiver_folder=/tmp/asapo/receiver/files Cleanup() { echo cleanup diff --git a/tests/automatic/full_chain/simple_chain/check_windows.bat b/tests/automatic/full_chain/simple_chain/check_windows.bat index 7f936e4de..bd7115b38 100644 --- a/tests/automatic/full_chain/simple_chain/check_windows.bat +++ b/tests/automatic/full_chain/simple_chain/check_windows.bat @@ -1,14 +1,14 @@ SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe" -set broker_database_name="test_run" -SET receiver_folder="c:\tmp\asapo\recevier\files" +set broker_database_name=test_run +SET receiver_folder="c:\tmp\asapo\receiver\files" -echo db.%broker_database_name%.insert({dummy:1})" | %mongo_exe% %broker_database_name% +echo db.%broker_database_name%.insert({dummy:1}) | %mongo_exe% %broker_database_name% c:\opt\consul\nomad run receiver.nmd c:\opt\consul\nomad run discovery.nmd c:\opt\consul\nomad run broker.nmd -ping 1.0.0.0 -n 1 -w 100 > nul +ping 1.0.0.0 -n 10 -w 100 > nul REM producer mkdir %receiver_folder% diff --git a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh index 8634b5485..817e76757 100644 --- a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh +++ b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh @@ -2,7 +2,7 @@ database_name=db_test mongo_database_name=test_run -receiver_folder=/tmp/asapo/recevier/files +receiver_folder=/tmp/asapo/receiver/files set -e trap Cleanup EXIT diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh index 814ae5f5b..d904c84f6 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh +++ b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh @@ -6,7 +6,7 @@ trap Cleanup EXIT database_name=db_test mongo_database_name=test_run -receiver_folder=/tmp/asapo/recevier/files +receiver_folder=/tmp/asapo/receiver/files Cleanup() { echo cleanup diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat index d6e8a0a4c..e27b681ba 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat +++ b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat @@ -1,6 +1,6 @@ SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe" SET database_name=test_run -SET receiver_folder="c:\tmp\asapo\recevier\files" +SET receiver_folder="c:\tmp\asapo\receiver\files" echo db.%database_name%.insert({dummy:1})" | %mongo_exe% %database_name% diff --git a/tests/automatic/settings/receiver.json.tpl b/tests/automatic/settings/receiver.json.tpl.lin similarity index 86% rename from tests/automatic/settings/receiver.json.tpl rename to tests/automatic/settings/receiver.json.tpl.lin index 8b62c2d30..8d98fd1ab 100644 --- a/tests/automatic/settings/receiver.json.tpl +++ b/tests/automatic/settings/receiver.json.tpl.lin @@ -8,5 +8,5 @@ "WriteToDisk":true, "WriteToDb":true, "LogLevel" : "debug", - "RootFolder" : "/tmp/asapo/recevier/files" + "RootFolder" : "/tmp/asapo/receiver/files" } diff --git a/tests/automatic/settings/receiver.json.tpl.win b/tests/automatic/settings/receiver.json.tpl.win new file mode 100644 index 000000000..d4cb5e038 --- /dev/null +++ b/tests/automatic/settings/receiver.json.tpl.win @@ -0,0 +1,12 @@ +{ + "MonitorDbAddress":"localhost:8086", + "MonitorDbName": "db_test", + "BrokerDbAddress":"localhost:27017", + "BrokerDbName": "test_run", + "ListenPort": {{ env "NOMAD_PORT_recv" }}, + "Tag": "{{ env "NOMAD_ADDR_recv" }}", + "WriteToDisk":true, + "WriteToDb":true, + "LogLevel" : "debug", + "RootFolder" : "c:\\tmp\\asapo\\receiver\\files" +} -- GitLab