lianetm commented on code in PR #15698: URL: https://github.com/apache/kafka/pull/15698#discussion_r1579555219
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManagerTest.java: ########## @@ -164,6 +165,23 @@ public void testHeartbeatOnStartup() { assertEquals(0, result2.unsentRequests.size()); } + @Test + public void testSuccessfulHeartbeatTiming() { + mockStableMember(); + NetworkClientDelegate.PollResult result = heartbeatRequestManager.poll(time.milliseconds()); + assertEquals(0, result.unsentRequests.size(), + "No heartbeat should be sent while interval has not expired"); + long currentTimeMs = time.milliseconds(); + assertEquals(heartbeatRequestState.timeToNextHeartbeatMs(currentTimeMs), result.timeUntilNextPollMs); + assertNextHeartbeatTiming(DEFAULT_HEARTBEAT_INTERVAL_MS); + + result = heartbeatRequestManager.poll(time.milliseconds()); + assertEquals(1, result.unsentRequests.size(), "A heartbeat should be sent when interval expires"); + NetworkClientDelegate.UnsentRequest inflightReq = result.unsentRequests.get(0); + inflightReq.handler().onComplete(createHeartbeatResponse(inflightReq, Errors.NONE)); + assertNextHeartbeatTiming(DEFAULT_HEARTBEAT_INTERVAL_MS); Review Comment: This relates to your comment above. You're right that we did not have the check to ensure the reset happened on the sent and not on the response, so I added above the check for the `timeToNextHeartbeatMs` that would fail if the timer is not reset on the send, with a specific message for it. That check covers it, but still I also added the steps for advance the timer just a bit, check that no HB is sent and that the time is updated with the difference, as you suggested. All done. ########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManagerTest.java: ########## @@ -164,6 +165,23 @@ public void testHeartbeatOnStartup() { assertEquals(0, result2.unsentRequests.size()); } + @Test + public void testSuccessfulHeartbeatTiming() { + mockStableMember(); + NetworkClientDelegate.PollResult result = heartbeatRequestManager.poll(time.milliseconds()); + assertEquals(0, result.unsentRequests.size(), + "No heartbeat should be sent while interval has not expired"); + long currentTimeMs = time.milliseconds(); + assertEquals(heartbeatRequestState.timeToNextHeartbeatMs(currentTimeMs), result.timeUntilNextPollMs); + assertNextHeartbeatTiming(DEFAULT_HEARTBEAT_INTERVAL_MS); + + result = heartbeatRequestManager.poll(time.milliseconds()); + assertEquals(1, result.unsentRequests.size(), "A heartbeat should be sent when interval expires"); Review Comment: Sure! I missed it. Added. -- 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