diff --git a/common/cpp/src/system_io/system_io_linux.cpp b/common/cpp/src/system_io/system_io_linux.cpp index 76342ac4f5b9eb4d71a30bd1185be26f6048dd37..a1013b29b74ede4a4112709bc661b15570fa1ecd 100644 --- a/common/cpp/src/system_io/system_io_linux.cpp +++ b/common/cpp/src/system_io/system_io_linux.cpp @@ -1,4 +1,5 @@ + #include <cstring> #include <dirent.h> @@ -236,11 +237,11 @@ SocketDescriptor SystemIO::_socket(int address_family, int socket_type, int sock } ssize_t SystemIO::_send(SocketDescriptor socket_fd, const void* buffer, size_t length) { - return ::send(socket_fd, buffer, length, MSG_DONTWAIT); + return ::send(socket_fd, buffer, length, MSG_NOSIGNAL); } ssize_t SystemIO::_recv(SocketDescriptor socket_fd, void* buffer, size_t length) { - return ::recv(socket_fd, buffer, length, MSG_DONTWAIT); + return ::recv(socket_fd, buffer, length, 0); } int SystemIO::_mkdir(const char* dirname) const { diff --git a/receiver/src/receiver.cpp b/receiver/src/receiver.cpp index 9a94afe45df43c47522ce68d850883976a6ad4ec..7588178739dc7cf4159fa559a160a9c3d8b688eb 100644 --- a/receiver/src/receiver.cpp +++ b/receiver/src/receiver.cpp @@ -61,7 +61,7 @@ void Receiver::StartNewConnectionInSeparateThread(int connection_socket_fd, cons }); if (thread) { - thread->detach(); + threads_.emplace_back(std::move(thread)); } return; } diff --git a/receiver/src/receiver.h b/receiver/src/receiver.h index c7435ce68aba8fa561e7a1df8086a75b40ca8149..bc90ac6780418754a664408dca651133f565067b 100644 --- a/receiver/src/receiver.h +++ b/receiver/src/receiver.h @@ -17,6 +17,7 @@ class Receiver { Error PrepareListener(std::string listener_address); void StartNewConnectionInSeparateThread(int connection_socket_fd, const std::string& address); void ProcessConnections(Error* err); + std::vector<std::unique_ptr<std::thread>> threads_; public: static const int kMaxUnacceptedConnectionsBacklog;//TODO: Read from config Receiver(const Receiver&) = delete; diff --git a/tests/automatic/CMakeLists.txt b/tests/automatic/CMakeLists.txt index b75349614935b69003f2bfec8a89da763bb46392..ea37ce600f63e9b4fe92fa165313b08a91f9aa11 100644 --- a/tests/automatic/CMakeLists.txt +++ b/tests/automatic/CMakeLists.txt @@ -31,4 +31,6 @@ add_subdirectory(producer) if (UNIX) add_subdirectory(high_avail) -endif() \ No newline at end of file +endif() + +add_subdirectory(bug_fixes) diff --git a/tests/automatic/bug_fixes/CMakeLists.txt b/tests/automatic/bug_fixes/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..91bd326920c5e3ddbad08c688448bb1239a2bbae --- /dev/null +++ b/tests/automatic/bug_fixes/CMakeLists.txt @@ -0,0 +1,5 @@ +if (UNIX) + add_subdirectory(receiver_cpu_usage) +endif() + +add_subdirectory(producer_send_after_restart) \ No newline at end of file diff --git a/tests/automatic/bug_fixes/producer_send_after_restart/CMakeLists.txt b/tests/automatic/bug_fixes/producer_send_after_restart/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..56a0067a3f0fb59f618d56247db84c8f4141ca15 --- /dev/null +++ b/tests/automatic/bug_fixes/producer_send_after_restart/CMakeLists.txt @@ -0,0 +1,16 @@ +set(TARGET_NAME producer_send_after_restart) + +################################ +# Testing +################################ +prepare_asapo() + +if (UNIX) + set (ROOT_PATH "/tmp/asapo/") +else() + set (ROOT_PATH "c:\\\\tmp\\\\asapo\\\\") +endif() + +configure_file(test.json.in test.json @ONLY) + +add_script_test("${TARGET_NAME}" "$<TARGET_FILE:event-monitor-producer-bin> $<TARGET_FILE:getnext_broker> $<TARGET_PROPERTY:asapo,EXENAME>" nomem) diff --git a/tests/automatic/bug_fixes/producer_send_after_restart/check_linux.sh b/tests/automatic/bug_fixes/producer_send_after_restart/check_linux.sh new file mode 100644 index 0000000000000000000000000000000000000000..250584350afff1ae5093aaafc55309c1eeefe88a --- /dev/null +++ b/tests/automatic/bug_fixes/producer_send_after_restart/check_linux.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +set -e + +trap Cleanup EXIT + +beamtime_id=asapo_test + +monitor_database_name=db_test +proxy_address=127.0.0.1:8400 + +beamline=test +receiver_root_folder=/tmp/asapo/receiver/files +receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id} + +mkdir -p /tmp/asapo/test_in/test1/ + +Cleanup() { + echo cleanup + rm -rf ${receiver_root_folder} + nomad stop nginx + nomad stop receiver + nomad stop discovery + nomad stop authorizer + echo "db.dropDatabase()" | mongo ${beamtime_id} +} + +nomad run nginx.nmd +nomad run authorizer.nmd +nomad run receiver.nmd +nomad run discovery.nmd + +sleep 1 + +#producer +mkdir -p ${receiver_folder} +$1 test.json &> output & +producerid=`echo $!` + +sleep 1 + +echo hello > /tmp/asapo/test_in/test1/file1 +sleep 1 +nomad stop receiver +sleep 1 +nomad run receiver.nmd + +echo hello > /tmp/asapo/test_in/test1/file1 +sleep 1 + +kill -s INT $producerid +sleep 0.5 +cat output +cat output | grep "Processed 2" + diff --git a/tests/automatic/bug_fixes/producer_send_after_restart/check_windows.bat b/tests/automatic/bug_fixes/producer_send_after_restart/check_windows.bat new file mode 100644 index 0000000000000000000000000000000000000000..162097f75524e5e86f98dfd5296e7eea57c08362 --- /dev/null +++ b/tests/automatic/bug_fixes/producer_send_after_restart/check_windows.bat @@ -0,0 +1,76 @@ + + +SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe" +SET beamtime_id=asapo_test +SET beamline=test +SET receiver_root_folder=c:\tmp\asapo\receiver\files +SET receiver_folder="%receiver_root_folder%\%beamline%\%beamtime_id%" + +set producer_short_name="%~nx1" + + +"%3" token -secret broker_secret.key %beamtime_id% > token +set /P token=< token + +set proxy_address="127.0.0.1:8400" + +echo db.%beamtime_id%.insert({dummy:1}) | %mongo_exe% %beamtime_id% + +c:\opt\consul\nomad run receiver.nmd +c:\opt\consul\nomad run authorizer.nmd +c:\opt\consul\nomad run discovery.nmd +c:\opt\consul\nomad run broker.nmd +c:\opt\consul\nomad run nginx.nmd + +ping 1.0.0.0 -n 10 -w 100 > nul + +REM producer +mkdir %receiver_folder% +mkdir c:\tmp\asapo\test_in\test1 +mkdir c:\tmp\asapo\test_in\test2 +start /B "" "%1" test.json + +ping 1.0.0.0 -n 3 -w 100 > nul + +echo hello > c:\tmp\asapo\test_in\test1\file1 +echo hello > c:\tmp\asapo\test_in\test1\file2 + +ping 1.0.0.0 -n 3 -w 100 > nul + +c:\opt\consul\nomad stop receiver +c:\opt\consul\nomad run receiver.nmd + +ping 1.0.0.0 -n 3 -w 100 > nul + + +echo hello > c:\tmp\asapo\test_in\test1\file3 + +ping 1.0.0.0 -n 10 -w 100 > nul + + +REM worker +"%2" %proxy_address% %beamtime_id% 2 %token% 1000 | findstr /c:"Processed 3 file(s)" || goto :error + + +goto :clean + +:error +call :clean +exit /b 1 + +:clean +c:\opt\consul\nomad stop receiver +c:\opt\consul\nomad stop discovery +c:\opt\consul\nomad stop broker +c:\opt\consul\nomad stop authorizer +c:\opt\consul\nomad stop nginx +rmdir /S /Q %receiver_root_folder% +rmdir /S /Q c:\tmp\asapo\test_in\test1 +rmdir /S /Q c:\tmp\asapo\test_in\test2 +Taskkill /IM "%producer_short_name%" /F + +del /f token +echo db.dropDatabase() | %mongo_exe% %beamtime_id% + + + diff --git a/tests/automatic/bug_fixes/producer_send_after_restart/test.json.in b/tests/automatic/bug_fixes/producer_send_after_restart/test.json.in new file mode 100644 index 0000000000000000000000000000000000000000..22b699c17deff35749c9c7ac59d82f8d62b473ae --- /dev/null +++ b/tests/automatic/bug_fixes/producer_send_after_restart/test.json.in @@ -0,0 +1,12 @@ +{ + "AsapoEndpoint":"localhost:8400", + "Tag":"test_tag", + "BeamtimeID":"asapo_test", + "Mode":"tcp", + "NThreads":1, + "LogLevel":"debug", + "RootMonitoredFolder":"@ROOT_PATH@test_in", + "MonitoredSubFolders":["test1"], + "IgnoreExtentions":["tmp"], + "RemoveAfterSend":true +} diff --git a/tests/automatic/bug_fixes/receiver_cpu_usage/CMakeLists.txt b/tests/automatic/bug_fixes/receiver_cpu_usage/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6bf9f8cfb1b26ca6b7fe568a41d61e641a76c11 --- /dev/null +++ b/tests/automatic/bug_fixes/receiver_cpu_usage/CMakeLists.txt @@ -0,0 +1,11 @@ +set(TARGET_NAME receiver_cpu_usage) + +################################ +# Testing +################################ +prepare_asapo() +set (ROOT_PATH "/tmp/asapo/") + +configure_file(test.json.in test.json @ONLY) + +add_script_test("${TARGET_NAME}" "$<TARGET_FILE:event-monitor-producer-bin> $<TARGET_FILE:getnext_broker> $<TARGET_PROPERTY:asapo,EXENAME>" nomem) diff --git a/tests/automatic/bug_fixes/receiver_cpu_usage/check_linux.sh b/tests/automatic/bug_fixes/receiver_cpu_usage/check_linux.sh new file mode 100644 index 0000000000000000000000000000000000000000..52228deb296efc93a858e6d28ee0e5b14a3499d3 --- /dev/null +++ b/tests/automatic/bug_fixes/receiver_cpu_usage/check_linux.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -e + +trap Cleanup EXIT + +beamtime_id=asapo_test + +monitor_database_name=db_test +proxy_address=127.0.0.1:8400 + +beamline=test +receiver_root_folder=/tmp/asapo/receiver/files +receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id} + +mkdir -p /tmp/asapo/test_in/test1/ + +Cleanup() { + echo cleanup + kill $producerid + rm -rf /tmp/asapo/test_in/test1 + rm -rf ${receiver_root_folder} + nomad stop nginx + nomad stop receiver + nomad stop discovery + nomad stop authorizer + echo "db.dropDatabase()" | mongo ${beamtime_id} +} + +nomad run nginx.nmd +nomad run authorizer.nmd +nomad run receiver.nmd +nomad run discovery.nmd + +sleep 1 + +#producer +mkdir -p ${receiver_folder} +$1 test.json & +producerid=`echo $!` + +sleep 1 + +echo hello > /tmp/asapo/test_in/test1/file1 + +sleep 5 + +usage=`top -b -n 1 | grep receiver | awk '{print int($9)'}` +echo CPU usage: $usage +if [ -z "$usage" ]; then +exit 1 +fi + +if (( $usage > 50 )); then + exit 1 +fi diff --git a/tests/automatic/bug_fixes/receiver_cpu_usage/test.json.in b/tests/automatic/bug_fixes/receiver_cpu_usage/test.json.in new file mode 100644 index 0000000000000000000000000000000000000000..22b699c17deff35749c9c7ac59d82f8d62b473ae --- /dev/null +++ b/tests/automatic/bug_fixes/receiver_cpu_usage/test.json.in @@ -0,0 +1,12 @@ +{ + "AsapoEndpoint":"localhost:8400", + "Tag":"test_tag", + "BeamtimeID":"asapo_test", + "Mode":"tcp", + "NThreads":1, + "LogLevel":"debug", + "RootMonitoredFolder":"@ROOT_PATH@test_in", + "MonitoredSubFolders":["test1"], + "IgnoreExtentions":["tmp"], + "RemoveAfterSend":true +} diff --git a/tests/automatic/settings/discovery_fixed_settings.json b/tests/automatic/settings/discovery_fixed_settings.json new file mode 100644 index 0000000000000000000000000000000000000000..25cba67824339d7c81a9d39b4a89d8356d4ea9bf --- /dev/null +++ b/tests/automatic/settings/discovery_fixed_settings.json @@ -0,0 +1,10 @@ +{ + "Mode": "consul", + "Receiver": { + "MaxConnections": 32 + }, + "Port": {{ env "NOMAD_PORT_discovery" }}, + "LogLevel":"debug" +} + +