m1a2st commented on code in PR #23348:
URL: https://github.com/apache/kafka/pull/23348#discussion_r3975192527


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/ShareHeartbeatRequestManagerTest.java:
##########
@@ -164,15 +164,46 @@ private void createHeartbeatStateAndRequestManager() {
     @Test
     public void testMaximumTimeToWaitWhenHeartbeatShouldBeSkippedDoesNotSpin() 
{
         
when(coordinatorRequestManager.coordinator()).thenReturn(Optional.of(new 
Node(1, "localhost", 9999)));
-        when(membershipManager.state()).thenReturn(MemberState.FATAL);
+        when(membershipManager.state()).thenReturn(MemberState.FENCED);
         when(membershipManager.shouldSkipHeartbeat()).thenReturn(true);
         
when(heartbeatRequestState.timeToNextHeartbeatMs(anyLong())).thenReturn(0L);
 
         long result = 
heartbeatRequestManager.maximumTimeToWait(time.milliseconds());
 
         assertTrue(result > 0,
             "maximumTimeToWait must be > 0 while heartbeats are skipped to 
avoid a busy-spin; got " + result);
-        assertEquals(DEFAULT_HEARTBEAT_INTERVAL_MS, result);
+        assertEquals(DEFAULT_RETRY_BACKOFF_MS, result);
+    }
+
+    @Test
+    public void testMaximumTimeToWaitWhenFatalReturnsMaxValue() {
+        
when(coordinatorRequestManager.coordinator()).thenReturn(Optional.of(new 
Node(1, "localhost", 9999)));
+        when(membershipManager.state()).thenReturn(MemberState.FATAL);
+
+        assertEquals(Long.MAX_VALUE, 
heartbeatRequestManager.maximumTimeToWait(time.milliseconds()),
+            "maximumTimeToWait should return Long.MAX_VALUE in the terminal 
FATAL state");
+    }
+
+    /**
+     * While bootstrap DNS resolution is still in progress the coordinator is 
unknown,
+     * and a member that wants to join has a zero heartbeat interval, since 
the interval is only
+     * learned from the first heartbeat response. maximumTimeToWait() must 
wait a retry backoff
+     * rather than the (zero) heartbeat interval; returning 0 busy-spins the 
application and
+     * network threads.
+     */
+    @Test
+    public void 
testMaximumTimeToWaitWhenJoiningAndCoordinatorUnknownDoesNotSpin() {

Review Comment:
   Thanks for bringing this up.



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