From e8f6ed0c00377147cd2d53a3efc82d6fcc2690d2 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Wed, 23 May 2018 18:18:45 +0200 Subject: [PATCH] more test in nomad --- CMakeLists.txt | 3 ++ CMakeModules/prepare_asapo.cmake | 11 +++++ config/nomad/discovery.nmd.in | 49 +++++++++++++++++++ config/nomad/receiver.nmd.in | 6 +-- .../dummy-data-producer/check_linux.sh | 2 +- producer/api/src/request_handler_tcp.cpp | 6 +-- .../unittests/test_request_handler_tcp.cpp | 25 ++++++++-- .../check_monitoring/CMakeLists.txt | 6 +-- .../check_monitoring/check_linux.sh | 11 ++--- .../transfer_single_file/CMakeLists.txt | 2 +- .../transfer_single_file/check_linux.sh | 11 +++-- .../settings/discovery_settings.json.tpl | 8 +++ 12 files changed, 111 insertions(+), 29 deletions(-) create mode 100644 CMakeModules/prepare_asapo.cmake create mode 100644 config/nomad/discovery.nmd.in create mode 100644 tests/automatic/settings/discovery_settings.json.tpl diff --git a/CMakeLists.txt b/CMakeLists.txt index db2c3fd22..58b498aa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,9 @@ include(astyle) include(testing_cpp) +include(prepare_asapo) + + if(BUILD_WORKER_TOOLS) set (BUILD_MONGODB_CLIENTLIB ON) endif() diff --git a/CMakeModules/prepare_asapo.cmake b/CMakeModules/prepare_asapo.cmake new file mode 100644 index 000000000..dcb4d5750 --- /dev/null +++ b/CMakeModules/prepare_asapo.cmake @@ -0,0 +1,11 @@ +function(prepare_asapo) + get_target_property(RECEIVER_DIR receiver-bin BINARY_DIR) + get_target_property(RECEIVER_NAME receiver-bin OUTPUT_NAME) + get_target_property(DISCOVERY_FULLPATH asapo-discovery EXENAME) + set(WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}) + 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}/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) +endfunction() + diff --git a/config/nomad/discovery.nmd.in b/config/nomad/discovery.nmd.in new file mode 100644 index 000000000..60a8a174e --- /dev/null +++ b/config/nomad/discovery.nmd.in @@ -0,0 +1,49 @@ +job "discovery" { + datacenters = ["dc1"] + + type = "service" + + group "group" { + count = 1 + + task "service" { + driver = "raw_exec" + + config { + command = "@DISCOVERY_FULLPATH@", + args = ["-config","${NOMAD_TASK_DIR}/discovery.json"] + } + + resources { + cpu = 500 # 500 MHz + memory = 256 # 256MB + network { + port "discovery" { + static = "5006" + } + } + } + + service { + name = "discovery" + port = "discovery" + check { + name = "alive" + type = "http" + path = "/receivers" + interval = "10s" + timeout = "2s" + initial_status = "passing" + } + } + + template { + source = "@WORK_DIR@/discovery.json.tpl" + destination = "local/discovery.json" + change_mode = "signal" + change_signal = "SIGHUP" + } + + } + } +} diff --git a/config/nomad/receiver.nmd.in b/config/nomad/receiver.nmd.in index 1d9c1675e..4559aedc7 100644 --- a/config/nomad/receiver.nmd.in +++ b/config/nomad/receiver.nmd.in @@ -11,7 +11,7 @@ job "receiver" { config { command = "/bin/bash", - args = ["-c", "mkdir files && exec ${RECEIVER_DIR}/${RECEIVER_NAME} receiver.json && rm -rf files"] + args = ["-c", "cd @WORK_DIR@ && exec @RECEIVER_DIR@/@RECEIVER_NAME@ ${NOMAD_TASK_DIR}/receiver.json"] } resources { @@ -35,8 +35,8 @@ job "receiver" { } template { - source = "${CMAKE_CURRENT_BINARY_DIR}/receiver.json.tpl" - destination = "receiver.json" + source = "@WORK_DIR@/receiver.json.tpl" + destination = "local/receiver.json" change_mode = "signal" change_signal = "SIGHUP" } diff --git a/examples/producer/dummy-data-producer/check_linux.sh b/examples/producer/dummy-data-producer/check_linux.sh index 51a141772..ec9b000ff 100644 --- a/examples/producer/dummy-data-producer/check_linux.sh +++ b/examples/producer/dummy-data-producer/check_linux.sh @@ -6,5 +6,5 @@ database_name=test_run #just test that it starts, no reciever is running -$@ 0.0.0.0 1 1 2>&1 | grep "Failed to connect" +$@ 0.0.0.0 1 1 1 1 2>&1 | grep "not successfully" diff --git a/producer/api/src/request_handler_tcp.cpp b/producer/api/src/request_handler_tcp.cpp index b382e0010..afbd2fd75 100644 --- a/producer/api/src/request_handler_tcp.cpp +++ b/producer/api/src/request_handler_tcp.cpp @@ -29,14 +29,11 @@ Error RequestHandlerTcp::SendHeaderAndData(const Request* request, const std::st Error io_error; io__->Send(sd_, &(request->header), sizeof(request->header), &io_error); if(io_error) { -// todo: add meaningful message to the io_error (here and below) - log__->Debug("cannot send header to " + receiver_address + " - " + io_error->Explain()); return io_error; } io__->Send(sd_, request->data, request->header.data_size, &io_error); if(io_error) { - log__->Debug("cannot send data to " + receiver_address + " - " + io_error->Explain()); return io_error; } @@ -48,7 +45,6 @@ Error RequestHandlerTcp::ReceiveResponse(const std::string& receiver_address) { SendDataResponse sendDataResponse; io__->Receive(sd_, &sendDataResponse, sizeof(sendDataResponse), &err); if(err != nullptr) { - log__->Debug("cannot receive response from " + receiver_address + " - " + err->Explain()); return err; } @@ -69,7 +65,6 @@ Error RequestHandlerTcp::TrySendToReceiver(const Request* request, const std::st err = ReceiveResponse(receiver_address); if (err) { - log__->Debug("cannot send data to " + receiver_address + ": " + err->Explain()); return err; } @@ -122,6 +117,7 @@ Error RequestHandlerTcp::ProcessRequestUnlocked(const Request* request) { if (err != nullptr && err != ProducerErrorTemplates::kFileIdAlreadyInUse) { io__->CloseSocket(sd_, nullptr); sd_ = kDisconnectedSocketDescriptor; + log__->Debug("cannot send data to " + receiver_uri + ": " + err->Explain()); log__->Debug("disconnected from " + receiver_uri); continue; } diff --git a/producer/api/unittests/test_request_handler_tcp.cpp b/producer/api/unittests/test_request_handler_tcp.cpp index 8eb3a24d6..440d41f59 100644 --- a/producer/api/unittests/test_request_handler_tcp.cpp +++ b/producer/api/unittests/test_request_handler_tcp.cpp @@ -138,7 +138,13 @@ void RequestHandlerTcpTests::ExpectFailSendHeader(bool only_once) { Return(-1) )); EXPECT_CALL(mock_logger, Debug(AllOf( - HasSubstr("cannot send header"), + HasSubstr("disconnected"), + HasSubstr(receivers_list[i]) + ) + )); + + EXPECT_CALL(mock_logger, Debug(AllOf( + HasSubstr("cannot send"), HasSubstr(receivers_list[i]) ) )); @@ -160,7 +166,13 @@ void RequestHandlerTcpTests::ExpectFailSendData(bool only_once) { Return(-1) )); EXPECT_CALL(mock_logger, Debug(AllOf( - HasSubstr("cannot send data"), + HasSubstr("disconnected"), + HasSubstr(receivers_list[i]) + ) + )); + + EXPECT_CALL(mock_logger, Debug(AllOf( + HasSubstr("cannot send"), HasSubstr(receivers_list[i]) ) )); @@ -183,7 +195,14 @@ void RequestHandlerTcpTests::ExpectFailReceive(bool only_once) { testing::Return(-1) )); EXPECT_CALL(mock_logger, Debug(AllOf( - HasSubstr("cannot receive"), + HasSubstr("disconnected"), + HasSubstr(receivers_list[i]) + ) + )); + + + EXPECT_CALL(mock_logger, Debug(AllOf( + HasSubstr("cannot send"), HasSubstr(receivers_list[i]) ) )); diff --git a/tests/automatic/producer_receiver/check_monitoring/CMakeLists.txt b/tests/automatic/producer_receiver/check_monitoring/CMakeLists.txt index 5b43f59df..45cadecbc 100644 --- a/tests/automatic/producer_receiver/check_monitoring/CMakeLists.txt +++ b/tests/automatic/producer_receiver/check_monitoring/CMakeLists.txt @@ -3,10 +3,6 @@ set(TARGET_NAME receiver) ################################ # Testing ################################ -get_target_property(RECEIVER_DIR receiver-bin BINARY_DIR) -get_target_property(RECEIVER_NAME receiver-bin OUTPUT_NAME) +prepare_asapo() -configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver.nmd.in receiver.nmd) -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 discovery.json COPYONLY) add_script_test("${TARGET_NAME}-monitoring" "$<TARGET_FILE:dummy-data-producer> $<TARGET_FILE:receiver-bin> $<TARGET_PROPERTY:asapo-discovery,EXENAME>" nomem) diff --git a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh index 39597e47a..7c7e9eb0a 100644 --- a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh +++ b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh @@ -10,19 +10,18 @@ trap Cleanup EXIT Cleanup() { echo cleanup influx -execute "drop database ${database_name}" -# kill $receiverid nomad stop receiver - kill $discoveryid + nomad stop discovery echo "db.dropDatabase()" | mongo ${mongo_database_name} + rm -rf files } +mkdir files + influx -execute "create database ${database_name}" nomad run receiver.nmd -sleep 0.3 - -nohup $3 -config discovery.json &>/dev/null & -discoveryid=`echo $!` +nomad run discovery.nmd sleep 1 diff --git a/tests/automatic/producer_receiver/transfer_single_file/CMakeLists.txt b/tests/automatic/producer_receiver/transfer_single_file/CMakeLists.txt index f745213b8..c74ddedc8 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/CMakeLists.txt +++ b/tests/automatic/producer_receiver/transfer_single_file/CMakeLists.txt @@ -3,5 +3,5 @@ set(TARGET_NAME transfer-single-file) ################################ # Testing ################################ -configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/receiver.json receiver.json COPYONLY) +prepare_asapo() add_script_test("${TARGET_NAME}" "$<TARGET_FILE:dummy-data-producer> $<TARGET_FILE:receiver-bin>" nomem) 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 48d4ff3dc..ae8edbf6c 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh +++ b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh @@ -9,16 +9,17 @@ database_name=test_run Cleanup() { echo cleanup rm -rf files - kill $receiverid + nomad stop receiver + nomad stop discovery echo "db.dropDatabase()" | mongo ${database_name} } -nohup $2 receiver.json &>/dev/null & -sleep 0.3 -receiverid=`echo $!` +nomad run receiver.nmd +nomad run discovery.nmd mkdir files -$1 localhost:4200 100 1 +$1 localhost:5006 100 1 1 0 + ls -ln files/1.bin | awk '{ print $5 }'| grep 102400 diff --git a/tests/automatic/settings/discovery_settings.json.tpl b/tests/automatic/settings/discovery_settings.json.tpl new file mode 100644 index 000000000..62cb9864b --- /dev/null +++ b/tests/automatic/settings/discovery_settings.json.tpl @@ -0,0 +1,8 @@ +{ + "MaxConnections": 32, + "Mode": "consul", + "Port": {{ env "NOMAD_PORT_discovery" }}, + "LogLevel":"debug" +} + + -- GitLab