Skip to content

Commit

Permalink
KAFKA-9662: Wait for consumer offset reset in throttle test to avoid …
Browse files Browse the repository at this point in the history
…losing early messages (#8227)
  • Loading branch information
rajinisivaram authored and mumrah committed Mar 6, 2020
1 parent 3f7af52 commit 573a149
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/kafkatest/services/console_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import itertools
import os

from ducktape.cluster.remoteaccount import RemoteCommandError
from ducktape.services.background_thread import BackgroundThreadService
from ducktape.utils.util import wait_until

from kafkatest.directory_layout.kafka_path import KafkaPathResolverMixin
from kafkatest.services.monitor.jmx import JmxMixin
Expand Down Expand Up @@ -296,3 +298,18 @@ def clean_node(self, node):

def java_class_name(self):
return "ConsoleConsumer"

def has_log_message(self, node, message):
try:
node.account.ssh("grep '%s' %s" % (message, ConsoleConsumer.LOG_FILE))
except RemoteCommandError:
return False
return True

def wait_for_offset_reset(self, node, topic, num_partitions):
for partition in range(num_partitions):
message = "Resetting offset for partition %s-%d" % (topic, partition)
wait_until(lambda: self.has_log_message(node, message),
timeout_sec=60,
err_msg="Offset not reset for partition %s-%d" % (topic, partition))

5 changes: 5 additions & 0 deletions tests/kafkatest/tests/produce_consume_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def start_producer_and_consumer(self):
err_msg="Consumer process took more than %d s to fork" %\
self.consumer_init_timeout_sec)

# If consuming only latest messages, wait for offset reset to ensure all messages are consumed
if not self.consumer.from_beginning:
self.consumer.wait_for_offset_reset(self.consumer.nodes[0], self.topic, self.num_partitions)


self.producer.start()
wait_until(lambda: self.producer.num_acked > 5,
timeout_sec=self.producer_start_timeout_sec,
Expand Down

0 comments on commit 573a149

Please sign in to comment.