From 921e0b4c90f7e23d6589637ada224bcd76da3e34 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Wed, 20 Jun 2018 16:03:20 +0200 Subject: [PATCH] test failure on wrong beamtime_id --- .../producer/dummy-data-producer/check_linux.sh | 2 +- .../dummy-data-producer/check_windows.bat | 2 +- .../dummy-data-producer/dummy_data_producer.cpp | 11 +++++++---- receiver/src/requests_dispatcher.cpp | 17 ++++++----------- receiver/unittests/test_requests_dispatcher.cpp | 12 ++++++------ .../full_chain/simple_chain/check_linux.sh | 2 +- .../full_chain/simple_chain/check_windows.bat | 2 +- .../check_monitoring/check_linux.sh | 2 +- .../transfer_single_file/check_linux.sh | 7 +++++-- .../transfer_single_file/check_windows.bat | 4 +++- 10 files changed, 32 insertions(+), 29 deletions(-) diff --git a/examples/producer/dummy-data-producer/check_linux.sh b/examples/producer/dummy-data-producer/check_linux.sh index e7301d29f..c9601daa1 100644 --- a/examples/producer/dummy-data-producer/check_linux.sh +++ b/examples/producer/dummy-data-producer/check_linux.sh @@ -12,7 +12,7 @@ rm -rf files mkdir files -$@ files beamtime_id 11 4 4 1 2>&1 | grep Rate +$@ files beamtime_id 11 4 4 1 10 2>&1 | grep Rate ls -ln files/0.bin | awk '{ print $5 }'| grep 11264 diff --git a/examples/producer/dummy-data-producer/check_windows.bat b/examples/producer/dummy-data-producer/check_windows.bat index 5cf58de58..6270913bc 100644 --- a/examples/producer/dummy-data-producer/check_windows.bat +++ b/examples/producer/dummy-data-producer/check_windows.bat @@ -2,7 +2,7 @@ SET folder=files mkdir %folder% -"%1" %folder% beamtime_id 11 4 4 1 2>&1 | findstr "Rate" || goto :error +"%1" %folder% beamtime_id 11 4 4 1 10 2>&1 | findstr "Rate" || goto :error FOR /F "usebackq" %%A IN ('%folder%\0.bin') DO set size=%%~zA if %size% NEQ 11264 goto :error diff --git a/examples/producer/dummy-data-producer/dummy_data_producer.cpp b/examples/producer/dummy-data-producer/dummy_data_producer.cpp index 31848cfbf..49769c2f7 100644 --- a/examples/producer/dummy-data-producer/dummy_data_producer.cpp +++ b/examples/producer/dummy-data-producer/dummy_data_producer.cpp @@ -19,6 +19,7 @@ struct Args { uint64_t iterations; uint64_t nthreads; uint64_t mode; + uint64_t timeout_sec; }; void PrintCommandArguments(const Args& args) { @@ -28,15 +29,17 @@ void PrintCommandArguments(const Args& args) { << "iterations: " << args.iterations << std::endl << "nthreads: " << args.nthreads << std::endl << "mode: " << args.mode << std::endl + << "timeout: " << args.timeout_sec << std::endl << std::endl; } void ProcessCommandArguments(int argc, char* argv[], Args* args) { - if (argc != 7) { + if (argc != 8) { std::cout << "Usage: " << argv[0] << - " <destination> <beamtime_id> <number_of_byte> <iterations> <nthreads> <mode 0 -t tcp, 1 - filesystem>" + " <destination> <beamtime_id> <number_of_byte> <iterations> <nthreads>" + " <mode 0 -t tcp, 1 - filesystem> <timeout (sec)>" << std::endl; exit(EXIT_FAILURE); } @@ -47,6 +50,7 @@ void ProcessCommandArguments(int argc, char* argv[], Args* args) { args->iterations = std::stoull(argv[4]); args->nthreads = std::stoull(argv[5]); args->mode = std::stoull(argv[6]); + args->timeout_sec = std::stoull(argv[7]); PrintCommandArguments(*args); return; } catch(std::exception& e) { @@ -96,7 +100,6 @@ std::unique_ptr<asapo::Producer> CreateProducer(const Args& args) { void WaitThreadsFinished(const Args& args) { uint64_t elapsed_ms = 0; - uint64_t timeout_sec = 180; while (true) { mutex.lock(); if (iterations_remained <= 0) { @@ -106,7 +109,7 @@ void WaitThreadsFinished(const Args& args) { mutex.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); elapsed_ms += 100; - if (elapsed_ms > timeout_sec * 1000) { + if (elapsed_ms > args.timeout_sec * 1000) { std::cerr << "Exit on timeout " << std::endl; exit(EXIT_FAILURE); } diff --git a/receiver/src/requests_dispatcher.cpp b/receiver/src/requests_dispatcher.cpp index 7639027eb..ddd2ad76b 100644 --- a/receiver/src/requests_dispatcher.cpp +++ b/receiver/src/requests_dispatcher.cpp @@ -47,23 +47,19 @@ Error RequestsDispatcher::ProcessRequest(const std::unique_ptr<Request>& request return handle_err == nullptr ? std::move(io_err) : std::move(handle_err); } -std::unique_ptr<Request> RequestsDispatcher::GetNextRequest(Error* err) -const noexcept { +std::unique_ptr<Request> RequestsDispatcher::GetNextRequest(Error* err) const noexcept { //TODO: to be overwritten with MessagePack (or similar) GenericRequestHeader generic_request_header; - statistics__-> - StartTimer(StatisticEntity::kNetwork); - io__-> - Receive(socket_fd_, &generic_request_header, - sizeof(GenericRequestHeader), err); + statistics__-> StartTimer(StatisticEntity::kNetwork); + io__-> Receive(socket_fd_, &generic_request_header, + sizeof(GenericRequestHeader), err); if(*err) { log__->Error("error getting next request from " + producer_uri_ + " - " + (*err)-> Explain() ); return nullptr; } - statistics__-> - StopTimer(); + statistics__-> StopTimer(); auto request = request_factory__->GenerateRequest(generic_request_header, socket_fd_, producer_uri_, err); if (*err) { log__->Error("error processing request from " + producer_uri_ + " - " + (*err)-> @@ -71,8 +67,7 @@ const noexcept { ); } - return - request; + return request; } diff --git a/receiver/unittests/test_requests_dispatcher.cpp b/receiver/unittests/test_requests_dispatcher.cpp index 356cc0597..561bed160 100644 --- a/receiver/unittests/test_requests_dispatcher.cpp +++ b/receiver/unittests/test_requests_dispatcher.cpp @@ -160,7 +160,7 @@ class RequestsDispatcherTests : public Test { } - void MockSendResponse(GenericNetworkResponse* response,bool error ) { + void MockSendResponse(GenericNetworkResponse* response, bool error ) { EXPECT_CALL(mock_logger, Debug(AllOf(HasSubstr("sending response to"), HasSubstr(connected_uri)))); ; EXPECT_CALL(mock_io, Send_t(_, _, _, _)).WillOnce( @@ -210,7 +210,7 @@ TEST_F(RequestsDispatcherTests, OkCreatetNextRequest) { TEST_F(RequestsDispatcherTests, ErrorProcessRequestErrorSend) { MockHandleRequest(true); - MockSendResponse(&response,true); + MockSendResponse(&response, true); auto err = dispatcher->ProcessRequest(request); @@ -220,7 +220,7 @@ TEST_F(RequestsDispatcherTests, ErrorProcessRequestErrorSend) { TEST_F(RequestsDispatcherTests, OkProcessRequestErrorSend) { MockHandleRequest(false); - MockSendResponse(&response,true); + MockSendResponse(&response, true); auto err = dispatcher->ProcessRequest(request); @@ -230,7 +230,7 @@ TEST_F(RequestsDispatcherTests, OkProcessRequestErrorSend) { TEST_F(RequestsDispatcherTests, OkProcessRequestSendOK) { MockHandleRequest(false); - MockSendResponse(&response,false); + MockSendResponse(&response, false); auto err = dispatcher->ProcessRequest(request); @@ -240,7 +240,7 @@ TEST_F(RequestsDispatcherTests, OkProcessRequestSendOK) { TEST_F(RequestsDispatcherTests, ProcessRequestReturnsAlreadyExist) { MockHandleRequest(true, asapo::IOErrorTemplates::kFileAlreadyExists.Generate()); - MockSendResponse(&response,false); + MockSendResponse(&response, false); auto err = dispatcher->ProcessRequest(request); @@ -251,7 +251,7 @@ TEST_F(RequestsDispatcherTests, ProcessRequestReturnsAlreadyExist) { TEST_F(RequestsDispatcherTests, ProcessRequestReturnsAuthorizationFailure) { MockHandleRequest(true, asapo::ReceiverErrorTemplates::kAuthorizationFailure.Generate()); - MockSendResponse(&response,false); + MockSendResponse(&response, false); auto err = dispatcher->ProcessRequest(request); diff --git a/tests/automatic/full_chain/simple_chain/check_linux.sh b/tests/automatic/full_chain/simple_chain/check_linux.sh index b92ce9c97..ef79fadba 100644 --- a/tests/automatic/full_chain/simple_chain/check_linux.sh +++ b/tests/automatic/full_chain/simple_chain/check_linux.sh @@ -36,7 +36,7 @@ sleep 1 #producer mkdir -p ${receiver_folder} -$1 localhost:8400 ${beamtime_id} 100 1000 4 0 & +$1 localhost:8400 ${beamtime_id} 100 1000 4 0 100 & #producerid=`echo $!` diff --git a/tests/automatic/full_chain/simple_chain/check_windows.bat b/tests/automatic/full_chain/simple_chain/check_windows.bat index 9be98343b..906f801f9 100644 --- a/tests/automatic/full_chain/simple_chain/check_windows.bat +++ b/tests/automatic/full_chain/simple_chain/check_windows.bat @@ -15,7 +15,7 @@ ping 1.0.0.0 -n 10 -w 100 > nul REM producer mkdir %receiver_folder% -start /B "" "%1" %proxy_address% %beamtime_id% 100 1000 4 0 +start /B "" "%1" %proxy_address% %beamtime_id% 100 1000 4 0 100 ping 1.0.0.0 -n 1 -w 100 > nul REM worker diff --git a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh index 5f20a5e25..8a5a5e517 100644 --- a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh +++ b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh @@ -29,7 +29,7 @@ nomad run nginx.nmd sleep 1 -$1 localhost:8400 ${beamtime_id} 100 112 4 0 +$1 localhost:8400 ${beamtime_id} 100 112 4 0 100 sleep 1 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 cfda6bff5..a5e357400 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh +++ b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh @@ -20,6 +20,7 @@ Cleanup() { } influx -execute "create database ${database_name}" +# create db before worker starts reading it. todo: git rid of it echo "db.${beamtime_id}.insert({dummy:1})" | mongo ${beamtime_id} nomad run authorizer.nmd @@ -29,7 +30,9 @@ nomad run discovery.nmd mkdir -p ${receiver_folder} -$1 localhost:8400 ${beamtime_id} 100 1 1 0 - +$1 localhost:8400 ${beamtime_id} 100 1 1 0 30 ls -ln ${receiver_folder}/1.bin | awk '{ print $5 }'| grep 102400 + + +$1 localhost:8400 wrong_beamtime_id 100 1 1 0 1 2>1 | grep "authorization failed" \ No newline at end of file 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 c069a5930..c1a0d0173 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat +++ b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat @@ -14,13 +14,15 @@ ping 1.0.0.0 -n 1 -w 100 > nul mkdir %receiver_folder% -%1 localhost:8400 %beamtime_id% 100 1 1 0 +%1 localhost:8400 %beamtime_id% 100 1 1 0 30 ping 1.0.0.0 -n 1 -w 100 > nul FOR /F "usebackq" %%A IN ('%receiver_folder%\1.bin') DO set size=%%~zA if %size% NEQ 102400 goto :error +%1 localhost:8400 wrong_id 100 1 1 0 10 | findstr /c:"Processed 1000 file(s)" || goto :error + goto :clean :error -- GitLab