bneradt commented on code in PR #13198:
URL: https://github.com/apache/trafficserver/pull/13198#discussion_r3293721198


##########
src/mgmt/rpc/server/unit_tests/test_rpcserver.cc:
##########
@@ -71,8 +72,32 @@ add_method_handler(const std::string &name, Func &&call)
 
 namespace
 {
-const std::string sockPath{"tests/var/jsonrpc20_test.sock"};
-const std::string lockPath{"tests/var/jsonrpc20_test.lock"};
+fs::path const &
+rpc_test_dir()
+{
+  static const fs::path dir = []() {
+    auto            path = fs::temp_directory_path() / 
fs::path("ats_jsonrpcserver_" + std::to_string(getpid()));
+    std::error_code ec;
+
+    fs::remove_all(path, ec);
+    ec.clear();
+    if (!fs::create_directories(path, ec, 0700) && ec) {
+      throw std::runtime_error{"Failed to create JSONRPC test directory: " + 
ec.message()};
+    }
+    return path;
+  }();
+
+  return dir;
+}
+
+std::string
+rpc_test_path(std::string_view filename)
+{
+  return rpc_test_dir().string() + "/" + std::string{filename};
+}
+
+const std::string sockPath{rpc_test_path("jsonrpc20_test.sock")};
+const std::string lockPath{rpc_test_path("jsonrpc20_test.lock")};

Review Comment:
   Done. The test now checks the generated socket path against the Unix socket 
path limit and falls back to a short /tmp-based directory when the environment 
temp path is too long. I also shortened the generated directory and socket 
names to leave more room.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to