Skip to content

Commit

Permalink
rptest/util: wait_for_local_storage_truncate robust on empty partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
andijcr committed Jun 28, 2023
1 parent f2e8d61 commit d99b3e6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/rptest/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ def wait_for_local_storage_truncate(redpanda,
redpanda.logger.debug(
"Waiting for local storage to be truncated to {target_bytes} bytes")

sizes: list[int] = []

def is_truncated():
storage = redpanda.storage(sizes=True)
nonlocal sizes
sizes = []
for node_partition in storage.partitions("kafka", topic):
if partition_idx is not None and node_partition.num != partition_idx:
Expand Down Expand Up @@ -269,11 +272,18 @@ def is_truncated():
threshold = target_bytes + 4096

# We expect to have measured size on at least one node, or this isn't meaningful
assert len(sizes) > 0
if len(sizes) == 0:
return False

return all(s <= threshold for s in sizes)

wait_until(is_truncated, timeout_sec=timeout_sec, backoff_sec=1)
wait_until(
is_truncated,
timeout_sec=timeout_sec,
backoff_sec=1,
err_msg=lambda:
f"truncation couldn't be verified for {topic=} and {target_bytes=}. last run partition_sizes={sizes}"
)


@contextmanager
Expand Down

0 comments on commit d99b3e6

Please sign in to comment.