Copilot commented on code in PR #13616:
URL: https://github.com/apache/trafficserver/pull/13616#discussion_r3970911674


##########
src/tsutil/unit_tests/test_Metrics.cc:
##########
@@ -707,3 +707,278 @@ TEST_CASE("Metrics id lookup is safe against concurrent 
creation", "[libtsapi][M
   // would mean the sweep above never left the first one.
   REQUIRE(hi - lo > Metrics::MAX_SIZE);
 }
+
+TEST_CASE("Metrics unlisting", "[libtsapi][Metrics]")
+{
+  auto &m = Metrics::instance();
+
+  SECTION("an unlisted metric is skipped by iteration")
+  {
+    Metrics::Counter::create("unlisted.iter.before");
+    auto target = Metrics::Counter::create("unlisted.iter.target");
+    Metrics::Counter::create("unlisted.iter.after");
+
+    REQUIRE(m.unlist(target));
+
+    bool saw_before = false, saw_target = false, saw_after = false;
+
+    for (auto &&[name, type, value] : m) {
+      saw_before |= (name == "unlisted.iter.before");
+      saw_target |= (name == "unlisted.iter.target");
+      saw_after  |= (name == "unlisted.iter.after");
+    }
+
+    REQUIRE(saw_before);
+    REQUIRE_FALSE(saw_target);
+    REQUIRE(saw_after);
+  }
+

Review Comment:
   This `TEST_CASE` uses many `SECTION`s while writing into the process-wide 
`Metrics::instance()` store. In Catch2, each `SECTION` re-runs the test case 
body but does not reset global/singleton state, so registrations accumulate 
across sections and can make the test suite increasingly stateful (and 
potentially slower/flakier if storage limits or name collisions are hit). 
Consider splitting these `SECTION`s into separate `TEST_CASE`s (so each runs 
only once) or using a test fixture/reset hook (if available) to clear the 
Metrics store between runs.



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