lianetm commented on code in PR #16638: URL: https://github.com/apache/kafka/pull/16638#discussion_r1686689029
########## clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java: ########## @@ -2093,14 +2093,27 @@ public void testEndOffsetsAuthenticationFailure(GroupProtocol groupProtocol) { assertThrows(AuthenticationException.class, () -> consumer.endOffsets(Collections.singleton(tp0))); } - // TODO: this test requires rebalance logic which is not yet implemented in the CONSUMER group protocol. - // Once it is implemented, this should use both group protocols. @ParameterizedTest - @EnumSource(value = GroupProtocol.class, names = "CLASSIC") - public void testPollAuthenticationFailure(GroupProtocol groupProtocol) { + @EnumSource(GroupProtocol.class) + public void testPollAuthenticationFailure(GroupProtocol groupProtocol) throws InterruptedException { final KafkaConsumer<String, String> consumer = consumerWithPendingAuthenticationError(groupProtocol); consumer.subscribe(singleton(topic)); - assertThrows(AuthenticationException.class, () -> consumer.poll(Duration.ZERO)); + + if (isAyncConsumer(groupProtocol)) { + // New consumer poll(ZERO) needs to wait for the event added by a call to poll, to be processed + // by the background thread, so it can realize there is authentication fail and then + // throw the AuthenticationException + TestUtils.waitForCondition(() -> { + try { + consumer.poll(Duration.ZERO); + return false; + } catch (AuthenticationException e) { + return true; + } + }, "Consumer was not able to update fetch positions on continuous calls with 0 timeout"); Review Comment: the message should be a bit different I would say. Even though it's all called from the `updateFechPositions`, the situation here is that we need to allow for the authentication exception (that is discovered in the background, when polling the `networkClientDelegate.maybePropagateMetadataError`), to appear in the app thread as an ErrorEvent (so that the AuthenticationException can be thrown on poll `processBackgroundEvents`). So maybe something like _Consumer was not able to discover metadata error on continous..._? -- 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