This is an automated email from the ASF dual-hosted git repository.

dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 253e046794 Unit-Tests: Make jsonrpc tests write the socket file inside 
the build (#11412)
253e046794 is described below

commit 253e046794fa20c2acc1e9b585469f97467129b8
Author: Damian Meden <[email protected]>
AuthorDate: Tue Jun 4 09:34:56 2024 +0200

    Unit-Tests: Make jsonrpc tests write the socket file inside the build 
(#11412)
    
    directory.
---
 src/mgmt/rpc/CMakeLists.txt                      |  2 ++
 src/mgmt/rpc/server/unit_tests/test_rpcserver.cc | 26 ++++--------------------
 2 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/src/mgmt/rpc/CMakeLists.txt b/src/mgmt/rpc/CMakeLists.txt
index 1d91928697..40211086d1 100644
--- a/src/mgmt/rpc/CMakeLists.txt
+++ b/src/mgmt/rpc/CMakeLists.txt
@@ -56,6 +56,8 @@ target_link_libraries(
 )
 
 if(BUILD_TESTING)
+  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/var)
+  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/config)
   add_executable(test_jsonrpc jsonrpc/unit_tests/unit_test_main.cc 
jsonrpc/unit_tests/test_basic_protocol.cc)
   target_link_libraries(
     test_jsonrpc ts::tsutil catch2::catch2 ts::rpcpublichandlers 
ts::jsonrpc_protocol libswoc::libswoc
diff --git a/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc 
b/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc
index ac294c7fbd..42aad4d8e2 100644
--- a/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc
+++ b/src/mgmt/rpc/server/unit_tests/test_rpcserver.cc
@@ -64,8 +64,8 @@ add_method_handler(const std::string &name, Func &&call)
   return rpc::JsonRPCManager::instance().add_method_handler(name, 
std::forward<Func>(call), nullptr, {});
 }
 } // namespace rpc
-static const std::string sockPath{"/tmp/jsonrpc20_test.sock"};
-static const std::string lockPath{"/tmp/jsonrpc20_test.lock"};
+static const std::string sockPath{"tests/var/jsonrpc20_test.sock"};
+static const std::string lockPath{"tests/var/jsonrpc20_test.lock"};
 static constexpr int     default_backlog{5};
 static constexpr int     default_maxRetriesOnTransientErrors{64};
 static constexpr auto    logTag{"rpc.test.client"};
@@ -143,20 +143,6 @@ DEFINE_JSONRPC_PROTO_FUNCTION(some_foo) // id, params
 }
 namespace
 {
-/* Create and return a path to a temporary sandbox directory. */
-fs::path
-getTemporaryDir()
-{
-  std::error_code ec;
-  fs::path        tmpDir  = fs::canonical(fs::temp_directory_path(), ec);
-  tmpDir                 /= "sandbox_XXXXXX";
-
-  char dirNameTemplate[tmpDir.string().length() + 1];
-  snprintf(dirNameTemplate, sizeof(dirNameTemplate), "%s", tmpDir.c_str());
-
-  return fs::path(mkdtemp(dirNameTemplate));
-}
-
 // Handy class to avoid manually disconnecting the socket.
 // TODO: should it also connect?
 struct ScopedLocalSocket : shared::rpc::IPCSocketClient {
@@ -505,7 +491,7 @@ struct LocalSocketTest : public trp::IPCSocketServer {
 };
 } // namespace
 
-TEST_CASE("Test configuration parsing. UDS values", "[string]")
+TEST_CASE("Test configuration parsing from a YAML node. UDS values", 
"[string]")
 {
   rpc::config::RPCConfig serverConfig;
 
@@ -527,8 +513,7 @@ TEST_CASE("Test configuration parsing. UDS values", 
"[string]")
 
 TEST_CASE("Test configuration parsing from a file. UDS Server", "[file]")
 {
-  fs::path sandboxDir = getTemporaryDir();
-  fs::path configPath = sandboxDir / "jsonrpc.yaml";
+  fs::path configPath = fs::path("tests/config") / "jsonrpc.yaml";
 
   // define here to later compare.
   std::string sockPathName{configPath.string() + "jsonrpc20_test2.sock"};
@@ -555,7 +540,4 @@ TEST_CASE("Test configuration parsing from a file. UDS 
Server", "[file]")
   REQUIRE(socket->get_conf().maxRetriesOnTransientErrors == 64);
   REQUIRE(socket->get_conf().sockPathName == sockPathName);
   REQUIRE(socket->get_conf().lockPathName == lockPathName);
-
-  std::error_code ec;
-  REQUIRE(fs::remove_all(sandboxDir, ec) > 0);
 }

Reply via email to