mjsax commented on code in PR #16373:
URL: https://github.com/apache/kafka/pull/16373#discussion_r1685169625


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManagerTest.java:
##########
@@ -153,6 +154,35 @@ public void cleanup() {
         }
     }
 
+    @Test
+    public void testHeartBeatRequestStateToStringBase() {
+        long retryBackoffMs = 100;
+        long retryBackoffMaxMs = 1000;
+        LogContext logContext = new LogContext();
+        HeartbeatRequestState heartbeatRequestState = new 
HeartbeatRequestState(
+                logContext,
+                time,
+                DEFAULT_HEARTBEAT_INTERVAL_MS,
+                retryBackoffMs,
+                retryBackoffMaxMs,
+                .2
+        );
+
+        RequestState requestState = new RequestState(
+                logContext,
+                HeartbeatRequestManager.HeartbeatRequestState.class.getName(),
+                retryBackoffMs,
+                retryBackoffMaxMs
+        );
+
+        String target = requestState.toStringBase() +
+                ", remainingMs=" + 
heartbeatRequestState.heartbeatTimer().remainingMs() +

Review Comment:
   We should not call `heartbeatRequestState.heartbeatTimer().remainingMs()` 
here -- it defeats the purpose of the test. Assume we except `remainingMs=500` 
but there is a bug -- this call will compute the incorrect `target` and we 
would compare it to itself. Never use the method you want to test, to compute 
the target result you compare to. That's an antipattern.
   
   It seem we have a mock `Time` object and `DEFAULT_HEARTBEAT_INTERVAL_MS` 
which we should use to compute this? Or maybe even hard-code it? If `Time` is a 
mock, and we don't advance `Time` we might even just know the expected result 
a-priori.
   
   For `DEFAULT_HEARTBEAT_INTERVAL_MS` is fine as this is a `final` variable.



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to