PapaCharlie commented on code in PR #1989:
URL: https://github.com/apache/zookeeper/pull/1989#discussion_r1204533964


##########
zookeeper-server/src/test/java/org/apache/zookeeper/ZKTestCase.java:
##########
@@ -114,4 +120,36 @@ public void waitFor(String msg, WaitForCondition 
condition, int timeout) throws
         fail(msg);
     }
 
-}
+    public static <T> void waitForMetric(String metricKey, Matcher<T> matcher) 
throws InterruptedException {
+        waitForMetric(metricKey, matcher, DEFAULT_METRIC_TIMEOUT);
+    }
+
+    public static <T> void waitForMetric(String metricKey, Matcher<T> matcher, 
int timeoutInSeconds) throws InterruptedException {
+        String errorMessage = String.format("metric \"%s\" failed to match 
after %d seconds",
+            metricKey, timeoutInSeconds);
+        waitFor(errorMessage, () -> {
+            @SuppressWarnings("unchecked")
+            T actual = (T) MetricsUtils.currentServerMetrics().get(metricKey);
+            if (!matcher.matches(actual)) {
+                Description description = new StringDescription();
+                matcher.describeMismatch(actual, description);
+                LOG.info("match failed for metric {}: {}", metricKey, 
description);

Review Comment:
   I updated the message. I think it makes sense to keep it as it is very 
useful when debugging, and in the success case the metric should resolve 
relatively quickly to the desired value so the log message may not even appear.
   
   I have changed it to be a bit more descriptive, let me know what you think



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