Copilot commented on code in PR #23687:
URL: https://github.com/apache/kafka/pull/23687#discussion_r4197113914


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/AbstractHeartbeatRequestManagerTest.java:
##########
@@ -331,37 +321,35 @@ public void testHeartbeatOnStartup() {
     @ParameterizedTest
     @ValueSource(booleans = {true, false})
     public void testSkippingHeartbeat(final boolean shouldSkipHeartbeat) {
-        // The initial heartbeatInterval is set to 0
-        createHeartbeatRequestStateWithZeroHeartbeatInterval();
-
         // Mocking notInGroup
         
when(membershipManager.shouldSkipHeartbeat()).thenReturn(shouldSkipHeartbeat);
 
-        NetworkClientDelegate.PollResult result = 
heartbeatRequestManager.poll(time.milliseconds());
-
         if (!shouldSkipHeartbeat) {
+            // Request an immediate heartbeat, regardless of the heartbeat 
timer.
+            when(membershipManager.shouldHeartbeatNow()).thenReturn(true);
+            NetworkClientDelegate.PollResult result = 
heartbeatRequestManager.poll(time.milliseconds());
             assertEquals(1, result.unsentRequests.size());
-            assertEquals(0, result.timeUntilNextPollMs);
+            assertEquals(DEFAULT_HEARTBEAT_INTERVAL_MS, 
result.timeUntilNextPollMs);
         } else {
+            NetworkClientDelegate.PollResult result = 
heartbeatRequestManager.poll(time.milliseconds());
             assertEquals(0, result.unsentRequests.size());
             assertEquals(Long.MAX_VALUE, result.timeUntilNextPollMs);
         }
     }
 
     /**
      * When the consumer uses manual partition assignment (assign()) instead 
of subscribe(), the
-     * member stays in UNSUBSCRIBED state indefinitely. Because heartbeats are 
skipped in that
-     * state and heartbeatIntervalMs initialises to 0, maximumTimeToWait used 
to return 0, causing
-     * a busy-loop in pollForFetches. Verify that maximumTimeToWait returns 
Long.MAX_VALUE whenever
-     * the member is in UNSUBSCRIBED state so the application thread can block 
for the full poll
-     * timeout.
+     * member stays in UNSUBSCRIBED state indefinitely. Heartbeats are skipped 
in that state.
+     * Verify that maximumTimeToWait returns Long.MAX_VALUE in that state so 
the application
+     * thread can block for the full poll timeout, while a joining member with 
a known coordinator
+     * can send immediately even before the initial heartbeat interval expires.
      */
     @ParameterizedTest
     @ValueSource(booleans = {true, false})
     public void testMaximumTimeToWaitWhenHeartbeatShouldBeSkipped(final 
boolean isUnsubscribed) {
-        // Start with zero heartbeat interval (simulates the initial state 
before any HB response)
-        createHeartbeatRequestStateWithZeroHeartbeatInterval();
         when(membershipManager.state()).thenReturn(isUnsubscribed ? 
MemberState.UNSUBSCRIBED : MemberState.JOINING);
+        // The implementation of shouldHeartbeatNow return true when 
MemberState is ACKNOWLEDGING, LEAVING, and JOINING.

Review Comment:
   Use subject-verb agreement in this comment: `implementation` is singular, so 
it should be “returns.”



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