Skip to content

Commit 4a2577b

Browse files
KAFKA-17395 Flaky test testMissingOffsetNoResetPolicy for new consumer (apache#17056)
In AsyncKafkaConsumer, FindCoordinatorRequest is sent by background thread. In MockClient#prepareResponseFrom, it only matches the response to a future request. If there is some race condition, FindCoordinatorResponse may not match to a FindCoordinatorRequest. It's better to put MockClient#prepareResponseFrom before the request to avoid flaky test. Reviewers: TaiJuWu <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent 3efa785 commit 4a2577b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,16 +924,14 @@ public void testMissingOffsetNoResetPolicy(GroupProtocol groupProtocol) throws I
924924
initMetadata(client, Collections.singletonMap(topic, 1));
925925
Node node = metadata.fetch().nodes().get(0);
926926

927-
consumer = newConsumer(groupProtocol, time, client, subscription, metadata, assignor,
928-
true, groupId, groupInstanceId, false);
929-
consumer.assign(singletonList(tp0));
930-
931927
client.prepareResponseFrom(FindCoordinatorResponse.prepareResponse(Errors.NONE, groupId, node), node);
932928
Node coordinator = new Node(Integer.MAX_VALUE - node.id(), node.host(), node.port());
933-
934-
// lookup committed offset and find nothing
935929
client.prepareResponseFrom(offsetResponse(Collections.singletonMap(tp0, -1L), Errors.NONE), coordinator);
936930

931+
consumer = newConsumer(groupProtocol, time, client, subscription, metadata, assignor,
932+
true, groupId, groupInstanceId, false);
933+
consumer.assign(singletonList(tp0));
934+
937935
if (groupProtocol == GroupProtocol.CONSUMER) {
938936
// New consumer poll(ZERO) needs to wait for the offset fetch event added by a call to poll, to be processed
939937
// by the background thread, so it can realize there are no committed offsets and then

0 commit comments

Comments
 (0)