cadonna commented on code in PR #14532: URL: https://github.com/apache/kafka/pull/14532#discussion_r1365517149
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/NetworkClientDelegateTest.java: ########## @@ -97,6 +99,29 @@ public void testTimeoutAfterSend() throws Exception { } } + @Test + public void testEnsureCorrectCompletionTimeOnFailure() { + NetworkClientDelegate.UnsentRequest unsentRequest = newUnsentFindCoordinatorRequest(); + long timeMs = time.milliseconds(); + unsentRequest.handler().onFailure(timeMs, new TimeoutException()); + + time.sleep(100); + assertEquals(timeMs, unsentRequest.handler().completionTimeMs()); + } + + @Test + public void testEnsureCorrectCompletionTimeOnComplete() throws IOException { + NetworkClientDelegate.UnsentRequest unsentRequest = newUnsentFindCoordinatorRequest(); + prepareFindCoordinatorResponse(Errors.NONE); + long timeMs = time.milliseconds(); + try (NetworkClientDelegate delegate = newNetworkClientDelegate()) { + delegate.send(unsentRequest); + delegate.poll(0, timeMs); + } + time.sleep(100); + assertEquals(timeMs, unsentRequest.handler().completionTimeMs()); + } + Review Comment: If you use a mock for the client response, the test becomes simpler. ```suggestion @Test public void testEnsureCorrectCompletionTimeOnComplete() { NetworkClientDelegate.UnsentRequest unsentRequest = newUnsentFindCoordinatorRequest(); long timeMs = time.milliseconds(); final ClientResponse response = mock(ClientResponse.class); when(response.receivedTimeMs()).thenReturn(timeMs); unsentRequest.handler().onComplete(response); time.sleep(100); assertEquals(timeMs, unsentRequest.handler().completionTimeMs()); } ``` -- 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