From 699b5740ea1f401895267d3ac2464da553218bd3 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Sat, 13 Nov 2021 15:51:57 +0100 Subject: [PATCH] fix tests --- .gitignore | 4 +-- common/cpp/include/asapo/common/io_error.h | 26 +++++++++---------- consumer/api/cpp/src/consumer_impl.cpp | 1 + .../net_server/rds_tcp_server.cpp | 1 + .../net_server/test_rds_tcp_server.cpp | 13 +--------- .../request_handler/test_request_handler.cpp | 4 +-- .../test_receiver_data_server.cpp | 10 ++----- .../test_receive_file_processor.cpp | 1 - .../automatic/producer/aai/check_windows.bat | 2 +- .../producer/python_api/check_windows.bat | 6 ++--- .../read_file_content/CMakeLists.txt | 4 +-- .../read_folder_content/CMakeLists.txt | 4 +-- .../read_string_from_file/CMakeLists.txt | 4 +-- .../read_subdirectories/CMakeLists.txt | 4 +-- .../write_data_to_file/CMakeLists.txt | 2 +- 15 files changed, 34 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index d7c8d680d..c04618641 100644 --- a/.gitignore +++ b/.gitignore @@ -54,9 +54,7 @@ .idea/**/libraries # CMake -cmake-build-debug/ -cmake-build-release/ -cmake-build-relwithdebinfo/ +cmake-build-*/ # Mongo Explorer plugin: .idea/**/mongoSettings.xml diff --git a/common/cpp/include/asapo/common/io_error.h b/common/cpp/include/asapo/common/io_error.h index ef15e6308..52245430b 100644 --- a/common/cpp/include/asapo/common/io_error.h +++ b/common/cpp/include/asapo/common/io_error.h @@ -36,39 +36,39 @@ using IOErrorTemplate = ServiceErrorTemplate<IOErrorType>; namespace IOErrorTemplates { auto const kUnknownIOError = IOErrorTemplate { - "Unknown Error", IOErrorType::kUnknownIOError + "unknown error", IOErrorType::kUnknownIOError }; auto const kFileNotFound = IOErrorTemplate { - "No such file or directory", IOErrorType::kFileNotFound + "no such file or directory", IOErrorType::kFileNotFound }; auto const kReadError = IOErrorTemplate { - "Read error", IOErrorType::kReadError + "read error", IOErrorType::kReadError }; auto const kBadFileNumber = IOErrorTemplate { - "Bad file number", IOErrorType::kBadFileNumber + "bad file number", IOErrorType::kBadFileNumber }; auto const kResourceTemporarilyUnavailable = IOErrorTemplate { - "Resource temporarily unavailable", IOErrorType::kResourceTemporarilyUnavailable + "resource temporarily unavailable", IOErrorType::kResourceTemporarilyUnavailable }; auto const kPermissionDenied = IOErrorTemplate { - "Permission denied", IOErrorType::kPermissionDenied + "permission denied", IOErrorType::kPermissionDenied }; auto const kUnsupportedAddressFamily = IOErrorTemplate { - "Unsupported address family", IOErrorType::kUnsupportedAddressFamily + "unsupported address family", IOErrorType::kUnsupportedAddressFamily }; auto const kInvalidAddressFormat = IOErrorTemplate { - "Invalid address format", IOErrorType::kInvalidAddressFormat + "invalid address format", IOErrorType::kInvalidAddressFormat }; auto const kAddressAlreadyInUse = IOErrorTemplate { - "Address already in use", IOErrorType::kAddressAlreadyInUse + "address already in use", IOErrorType::kAddressAlreadyInUse }; auto const kConnectionRefused = IOErrorTemplate { - "Connection refused", IOErrorType::kConnectionRefused + "connection refused", IOErrorType::kConnectionRefused }; auto const kNotConnected = IOErrorTemplate { - "Not connected", IOErrorType::kNotConnected + "not connected", IOErrorType::kNotConnected }; auto const kConnectionResetByPeer = IOErrorTemplate { @@ -101,11 +101,11 @@ auto const kSocketOperationValueOutOfBound = IOErrorTemplate { }; auto const kAddressNotValid = IOErrorTemplate { - "Address not valid", IOErrorType::kAddressNotValid + "address not valid", IOErrorType::kAddressNotValid }; auto const kBrokenPipe = IOErrorTemplate { - "Broken pipe/connection", IOErrorType::kBrokenPipe + "broken pipe/connection", IOErrorType::kBrokenPipe }; diff --git a/consumer/api/cpp/src/consumer_impl.cpp b/consumer/api/cpp/src/consumer_impl.cpp index 18abec7a7..7f623e67b 100644 --- a/consumer/api/cpp/src/consumer_impl.cpp +++ b/consumer/api/cpp/src/consumer_impl.cpp @@ -222,6 +222,7 @@ Error ConsumerImpl::ProcessDiscoverServiceResult(Error err, std::string* uri_to_ return err; } auto ret_err = ConsumerErrorTemplates::kUnavailableService.Generate(std::move(err)); + ret_err->AddDetails("destination",endpoint_); return ret_err; } return nullptr; diff --git a/receiver/src/receiver_data_server/net_server/rds_tcp_server.cpp b/receiver/src/receiver_data_server/net_server/rds_tcp_server.cpp index e1d983add..6f24fc62a 100644 --- a/receiver/src/receiver_data_server/net_server/rds_tcp_server.cpp +++ b/receiver/src/receiver_data_server/net_server/rds_tcp_server.cpp @@ -51,6 +51,7 @@ ReceiverDataServerRequestPtr RdsTcpServer::ReadRequest(SocketDescriptor socket, io__->Receive(socket, &header, sizeof(GenericRequestHeader), &io_err); if (io_err == GeneralErrorTemplates::kEndOfFile) { + *err = std::move(io_err); CloseSocket(socket); return nullptr; } else if (io_err) { diff --git a/receiver/unittests/receiver_data_server/net_server/test_rds_tcp_server.cpp b/receiver/unittests/receiver_data_server/net_server/test_rds_tcp_server.cpp index 22a0aae33..a80f9f0c8 100644 --- a/receiver/unittests/receiver_data_server/net_server/test_rds_tcp_server.cpp +++ b/receiver/unittests/receiver_data_server/net_server/test_rds_tcp_server.cpp @@ -126,10 +126,6 @@ void RdsTCPServerTests::MockReceiveRequest(bool ok ) { DoAll(SetArgPointee<3>(ok ? nullptr : asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), Return(0)) ); - if (!ok) { - std::string connected_uri = std::to_string(conn); - EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("request"), HasSubstr(connected_uri)))); - } } } @@ -163,8 +159,7 @@ void RdsTCPServerTests::ExpectReceiveOk() { A_ReceiveData(asapo::kOpcodeGetBufferData, conn), testing::ReturnArg<2>() )); - EXPECT_CALL(mock_logger, Debug(AllOf(HasSubstr("request"), HasSubstr("id: " + std::to_string(conn)), - HasSubstr("opcode: " + std::to_string(asapo::kOpcodeGetBufferData))))); + EXPECT_CALL(mock_logger, Debug(AllOf(HasSubstr("request"), HasSubstr(std::to_string(conn))))); } } @@ -249,8 +244,6 @@ TEST_F(RdsTCPServerTests, SendResponse) { Return(1) )); - EXPECT_CALL(mock_logger, Error(HasSubstr("cannot send"))); - auto err = tcp_server.SendResponse(&expectedRequest, &tmp); ASSERT_THAT(err, Ne(nullptr)); @@ -272,8 +265,6 @@ TEST_F(RdsTCPServerTests, SendResponseAndSlotData_SendResponseError) { testing::SetArgPointee<3>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), Return(0) )); - EXPECT_CALL(mock_logger, Error(HasSubstr("cannot send"))); - auto err = tcp_server.SendResponseAndSlotData(&expectedRequest, &tmp, &expectedMeta); ASSERT_THAT(err, Ne(nullptr)); @@ -298,8 +289,6 @@ TEST_F(RdsTCPServerTests, SendResponseAndSlotData_SendError) { Return(0) )); - EXPECT_CALL(mock_logger, Error(HasSubstr("cannot send"))); - auto err = tcp_server.SendResponseAndSlotData(&expectedRequest, &tmp, &expectedMeta); ASSERT_THAT(err, Ne(nullptr)); diff --git a/receiver/unittests/receiver_data_server/request_handler/test_request_handler.cpp b/receiver/unittests/receiver_data_server/request_handler/test_request_handler.cpp index fb85f18e5..b6a0951a3 100644 --- a/receiver/unittests/receiver_data_server/request_handler/test_request_handler.cpp +++ b/receiver/unittests/receiver_data_server/request_handler/test_request_handler.cpp @@ -112,7 +112,7 @@ TEST_F(RequestHandlerTests, RequestAlwaysReady) { TEST_F(RequestHandlerTests, ProcessRequest_WrongOpCode) { request.header.op_code = asapo::kOpcodeUnknownOp; - MockSendResponse(asapo::kNetErrorWrongRequest, false); + MockSendResponse(asapo::kNetErrorWrongRequest, true); EXPECT_CALL(mock_net, HandleAfterError_t(expected_source_id)); EXPECT_CALL(mock_logger, Error(HasSubstr("wrong request"))); @@ -124,7 +124,7 @@ TEST_F(RequestHandlerTests, ProcessRequest_WrongOpCode) { TEST_F(RequestHandlerTests, ProcessRequest_WrongClientVersion) { strcpy(request.header.api_version, "v0.2"); - MockSendResponse(asapo::kNetErrorNotSupported, false); + MockSendResponse(asapo::kNetErrorNotSupported, true); EXPECT_CALL(mock_net, HandleAfterError_t(expected_source_id)); EXPECT_CALL(mock_logger, Error(HasSubstr("unsupported client"))); diff --git a/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp b/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp index b3ce88a40..004915c1f 100644 --- a/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp +++ b/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp @@ -94,8 +94,6 @@ TEST_F(ReceiverDataServerTests, TimeoutGetNewRequests) { data_server.Run(); } - - TEST_F(ReceiverDataServerTests, ErrorGetNewRequests) { EXPECT_CALL(mock_net, GetNewRequests_t(_)).WillOnce( DoAll(SetArgPointee<0>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), @@ -103,9 +101,7 @@ TEST_F(ReceiverDataServerTests, ErrorGetNewRequests) { ) ); - auto errtext = asapo::IOErrorTemplates::kUnknownIOError.Generate()->Explain(); - - EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("stopped"), HasSubstr(errtext)))); + EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("stopped"), HasSubstr("unknown error")))); data_server.Run(); } @@ -121,9 +117,7 @@ TEST_F(ReceiverDataServerTests, ErrorAddingRequests) { Return(asapo::ReceiverDataServerErrorTemplates::kMemoryPool.Generate("cannot add request to pool").release()) ); - auto errtext = asapo::ReceiverDataServerErrorTemplates::kMemoryPool.Generate("cannot add request to pool")->Explain(); - - EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("stopped"), HasSubstr(errtext)))); + EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("stopped"), HasSubstr("pool")))); data_server.Run(); } 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 81d8aa890..518ef7d18 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 @@ -120,7 +120,6 @@ TEST_F(ReceiveFileProcessorTests, WritesToLog) { .WillOnce(Return(nullptr)); EXPECT_CALL(mock_logger, Debug(AllOf(HasSubstr("received file"), - HasSubstr(expected_file_name), HasSubstr(std::to_string(expected_file_size)) ) ) diff --git a/tests/automatic/producer/aai/check_windows.bat b/tests/automatic/producer/aai/check_windows.bat index 28a3e3c9d..36373feda 100644 --- a/tests/automatic/producer/aai/check_windows.bat +++ b/tests/automatic/producer/aai/check_windows.bat @@ -33,7 +33,7 @@ echo %NUM% | findstr 3 || goto error for /F %%N in ('find /C "reauthorization" ^< "out"') do set NUM=%%N echo %NUM% | findstr 1 || goto error -for /F %%N in ('find /C "} error: server warning, context: response:duplicated request" ^< "out"') do set NUM=%%N +for /F %%N in ('find /C "} error: server warning, details: response:duplicated request" ^< "out"') do set NUM=%%N echo %NUM% | findstr 1 || goto error goto :clean diff --git a/tests/automatic/producer/python_api/check_windows.bat b/tests/automatic/producer/python_api/check_windows.bat index 5920874f0..78389910e 100644 --- a/tests/automatic/producer/python_api/check_windows.bat +++ b/tests/automatic/producer/python_api/check_windows.bat @@ -20,13 +20,13 @@ set NUM=0 for /F %%N in ('find /C "successfuly sent" ^< "out"') do set NUM=%%N echo %NUM% | findstr 17 || goto error -for /F %%N in ('find /C "} error: wrong input, context: response:error: Bad request, message: already have record with same id" ^< "out"') do set NUM=%%N +for /F %%N in ('find /C "} error: wrong input, details: response:error: Bad request, message: already have record with same id" ^< "out"') do set NUM=%%N echo %NUM% | findstr 2 || goto error -for /F %%N in ('find /C "} error: server warning, context: response:ignoring duplicate record" ^< "out"') do set NUM=%%N +for /F %%N in ('find /C "} error: server warning, details: response:ignoring duplicate record" ^< "out"') do set NUM=%%N echo %NUM% | findstr 2 || goto error -for /F %%N in ('find /C "} error: server warning, context: response:duplicated request" ^< "out"') do set NUM=%%N +for /F %%N in ('find /C "} error: server warning, details: response:duplicated request" ^< "out"') do set NUM=%%N echo %NUM% | findstr 1 || goto error diff --git a/tests/automatic/system_io/read_file_content/CMakeLists.txt b/tests/automatic/system_io/read_file_content/CMakeLists.txt index 5f302cdb1..c4a37e863 100644 --- a/tests/automatic/system_io/read_file_content/CMakeLists.txt +++ b/tests/automatic/system_io/read_file_content/CMakeLists.txt @@ -17,6 +17,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) add_test_setup_cleanup(${TARGET_NAME}) add_integration_test(${TARGET_NAME} readfile "test/1 123") add_integration_test(${TARGET_NAME} readfile_unkown_size "test/2 unknown_size") -add_integration_test(${TARGET_NAME} filenotfound "test_notexist error:Nosuchfileordirectory,context:name:test_notexist") -add_integration_test(${TARGET_NAME} filenoaccess "file_noaccess error:Permissiondenied,context:name:file_noaccess") +add_integration_test(${TARGET_NAME} filenotfound "test_notexist error:nosuchfileordirectory,details:name:test_notexist") +add_integration_test(${TARGET_NAME} filenoaccess "file_noaccess error:permissiondenied,details:name:file_noaccess") diff --git a/tests/automatic/system_io/read_folder_content/CMakeLists.txt b/tests/automatic/system_io/read_folder_content/CMakeLists.txt index 222ab4585..c6938f921 100644 --- a/tests/automatic/system_io/read_folder_content/CMakeLists.txt +++ b/tests/automatic/system_io/read_folder_content/CMakeLists.txt @@ -27,6 +27,6 @@ ELSE() ENDIF(WIN32) -add_integration_test(${TARGET_NAME} foldernotfound "test_notexist error:Nosuchfileordirectory,details:name:test_notexist") -add_integration_test(${TARGET_NAME} foldernoaccess "test_noaccess1 error:Permissiondenied,details:name:test_noaccess1") +add_integration_test(${TARGET_NAME} foldernotfound "test_notexist error:nosuchfileordirectory,details:name:test_notexist") +add_integration_test(${TARGET_NAME} foldernoaccess "test_noaccess1 error:permissiondenied,details:name:test_noaccess1") diff --git a/tests/automatic/system_io/read_string_from_file/CMakeLists.txt b/tests/automatic/system_io/read_string_from_file/CMakeLists.txt index 358742805..35645add6 100644 --- a/tests/automatic/system_io/read_string_from_file/CMakeLists.txt +++ b/tests/automatic/system_io/read_string_from_file/CMakeLists.txt @@ -16,6 +16,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) add_test_setup_cleanup(${TARGET_NAME}) add_integration_test(${TARGET_NAME} readfile "test/1 123") -add_integration_test(${TARGET_NAME} filenotfound "test_notexist error:Nosuchfileordirectory,details:name:test_notexist") -add_integration_test(${TARGET_NAME} filenoaccess "file_noaccess error:Permissiondenied,details:name:file_noaccess") +add_integration_test(${TARGET_NAME} filenotfound "test_notexist error:nosuchfileordirectory,details:name:test_notexist") +add_integration_test(${TARGET_NAME} filenoaccess "file_noaccess error:permissiondenied,details:name:file_noaccess") diff --git a/tests/automatic/system_io/read_subdirectories/CMakeLists.txt b/tests/automatic/system_io/read_subdirectories/CMakeLists.txt index 837b0c6b1..4ec44441e 100644 --- a/tests/automatic/system_io/read_subdirectories/CMakeLists.txt +++ b/tests/automatic/system_io/read_subdirectories/CMakeLists.txt @@ -27,6 +27,6 @@ ELSE() ENDIF(WIN32) -add_integration_test(${TARGET_NAME} foldernotfound "test_notexist error:Nosuchfileordirectory,details:name:test_notexist") -add_integration_test(${TARGET_NAME} foldernoaccess "test_noaccess1 error:Permissiondenied,details:name:test_noaccess1") +add_integration_test(${TARGET_NAME} foldernotfound "test_notexist error:nosuchfileordirectory,details:name:test_notexist") +add_integration_test(${TARGET_NAME} foldernoaccess "test_noaccess1 error:permissiondenied,details:name:test_noaccess1") diff --git a/tests/automatic/system_io/write_data_to_file/CMakeLists.txt b/tests/automatic/system_io/write_data_to_file/CMakeLists.txt index 3e7a13c46..c062aa993 100644 --- a/tests/automatic/system_io/write_data_to_file/CMakeLists.txt +++ b/tests/automatic/system_io/write_data_to_file/CMakeLists.txt @@ -22,5 +22,5 @@ else () endif() add_integration_test(${TARGET_NAME} writetwice "test_file ok dummy" nomem) -add_integration_test(${TARGET_NAME} dirnoaccess "test_noaccess/test_file error error:Permissiondenied,context:name:test_noaccess/test_file" nomem) +add_integration_test(${TARGET_NAME} dirnoaccess "test_noaccess/test_file error error:permissiondenied,details:name:test_noaccess/test_file" nomem) -- GitLab