brbzull0 commented on code in PR #13649:
URL: https://github.com/apache/trafficserver/pull/13649#discussion_r3955899250


##########
src/mgmt/rpc/server/unit_tests/test_rpcserver.cc:
##########
@@ -77,6 +77,42 @@ add_method_handler(const std::string &name, Func &&call)
 {
   return rpc::JsonRPCManager::instance().add_method_handler(name, 
std::forward<Func>(call), nullptr, {});
 }
+
+/// Registers a method handler and removes it when the scope ends.
+///
+/// Catch2 re-runs a TEST_CASE body once per leaf SECTION. Registering at the 
top of the body and
+/// removing at the bottom only works while every assertion passes: REQUIRE is 
fatal, so a failure
+/// inside a SECTION unwinds before the trailing removal and the handler 
survives into the next
+/// SECTION's run, where re-registering it fails. One real failure then 
reports as two, and the
+/// second points at a registration that was never the problem.
+class ScopedMethodHandler
+{
+public:
+  template <typename Func> ScopedMethodHandler(std::string name, Func &&call) 
: _name{std::move(name)}
+  {
+    _registered = rpc::add_method_handler(_name, std::forward<Func>(call));
+  }

Review Comment:
   Leaving this one as is -- the formatter will not keep it.
   
   `.clang-format` sets:
   
   ```
   AlwaysBreakTemplateDeclarations: MultiLine
   ```
   
   `MultiLine` breaks the template declaration only when the declaration itself
   spans more than one line. `add_method_handler()` and `chunk_impl()` split
   because their return type sits on its own line, which makes them multi-line.
   A constructor has no return type, and this one fits in 101 columns, so it 
stays
   joined.
   
   I tried the suggested form and ran the project formatter over it:
   
   ```
   before:  template <typename Func>
            ScopedMethodHandler(std::string name, Func &&call) : 
_name{std::move(name)}
   
   after:   template <typename Func> ScopedMethodHandler(std::string name, Func 
&&call) : _name{std::move(name)}
   ```
   
   clang-format rejoins it, so the split would not survive the Format CI job.



-- 
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