Copilot commented on code in PR #8534:
URL: https://github.com/apache/hadoop/pull/8534#discussion_r3366753879


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerLongRunningTasks.java:
##########
@@ -823,17 +824,20 @@ public void testBalancerMetricsDuplicate() throws 
Exception {
 
       // Throw an error when we double-initialize BalancerMetrics
       DefaultMetricsSystem.setMiniClusterMode(false);
-      MetricsSystem instance = DefaultMetricsSystem.instance();
-      // Avoid the impact of cluster metric, remove cluster JvmMetrics
-      instance.unregisterSource("JvmMetrics");
-
-      final BalancerParameters balancerParameters = Balancer.Cli.parse(new 
String[] {
-          "-policy", BalancingPolicy.Node.INSTANCE.getName(),
-          "-threshold", "10",
-      });
-      int r = Balancer.run(namenodes, nsIds, balancerParameters, conf);
-      assertEquals(ExitStatus.SUCCESS.getExitCode(), r);
-      DefaultMetricsSystem.setMiniClusterMode(true);
+      try {
+        MetricsSystem instance = DefaultMetricsSystem.instance();
+        // Avoid the impact of cluster metric, remove cluster JvmMetrics

Review Comment:
   The test forces `setMiniClusterMode(false)` but always restores to `true`, 
which can change global state if the previous value wasn’t `true` (and differs 
from the pattern used elsewhere in the codebase). Capture the prior value via 
`DefaultMetricsSystem.inMiniClusterMode()` and restore that in the `finally`.



##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerLongRunningTasks.java:
##########
@@ -110,6 +110,7 @@ public void shutdown() throws Exception {
       cluster.shutdown();
       cluster = null;
     }
+    DefaultMetricsSystem.shutdown();

Review Comment:
   `DefaultMetricsSystem.shutdown()` won’t run if `cluster.shutdown()` throws, 
which can leave the metrics singleton in a dirty state (the flake you’re 
addressing) and potentially affect subsequent tests. Wrap the cluster shutdown 
in a `try/finally` so metrics are always reset, and null out `cluster` in the 
`finally` to avoid reuse after a failed shutdown.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to