Copilot commented on code in PR #30044:
URL: https://github.com/apache/flink/pull/30044#discussion_r4649790023


##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/metrics/UdfMetricsTest.java:
##########
@@ -134,6 +139,45 @@ void metricsAreIndependentPerUdf() {
         assertThat(secondCounter.getCount()).isZero();
     }
 
+    @Test
+    void restartedOperatorGetsNewHandle() {
+        MetricGroup firstAttempt = 
metricListener.getMetricGroup().addGroup("operator");
+        UdfMetrics first = UdfMetrics.register(firstAttempt, "myUdf", 1);
+        ((AbstractMetricGroup<?>) firstAttempt).close();
+
+        // Same scope as the closed group, but a new group instance, as for a 
restarted task.
+        MetricGroup secondAttempt = 
metricListener.getMetricGroup().addGroup("operator");
+        UdfMetrics second = UdfMetrics.register(secondAttempt, "myUdf", 1);
+        second.update(10L);
+
+        assertThat(second).isNotSameAs(first);
+        assertThat(
+                        metricListener
+                                .getHistogram("operator", "udf", "myUdf", 
"udfProcessingTime")
+                                .get()
+                                .getCount())
+                .isEqualTo(1L);
+    }
+
+    @Test
+    void doesNotRetainOperatorMetricGroup() throws Exception {
+        WeakReference<MetricGroup> operatorGroup = 
registerOnUnreferencedGroup();
+
+        for (int i = 0; i < 10 && operatorGroup.get() != null; i++) {
+            System.gc();
+            Thread.sleep(50);
+        }

Review Comment:
   This test can fail even when the cache does not retain the group: 
System.gc() is only a request, and ten requests plus 500 ms of sleeping do not 
guarantee that the JVM will collect the weakly reachable object. Please use a 
GC-aware test helper that waits for confirmed collection with a generous 
timeout (and handles disabled explicit GC), rather than treating this short 
polling window as evidence of a leak.



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