Skip to content

Commit

Permalink
tests,backup: fix flakiness by using current timestamps
Browse files Browse the repository at this point in the history
Using some (old) fixed timestamps when producing messages was causing the
messages to be automatically deleted because past message retention.
I think most of the time the test was managing to complete successfully
before the retention kicked in, making it fail only sometimes.
  • Loading branch information
davide-armand committed Oct 25, 2024
1 parent 60b5db6 commit bfc96a2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/integration/backup/test_v3_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ def test_roundtrip_from_kafka_state(
admin_client.update_topic_config(new_topic.topic, {"max.message.bytes": "999"})

# Populate topic.
producer.send(
first_record_fut = producer.send(
new_topic.topic,
key=b"bar",
value=b"foo",
partition=0,
timestamp=1683474641,
)
producer.send(
second_record_fut = producer.send(
new_topic.topic,
key=b"foo",
value=b"bar",
Expand All @@ -135,10 +134,12 @@ def test_roundtrip_from_kafka_state(
("some-header", b"some header value"),
("other-header", b"some other header value"),
],
timestamp=1683474657,
)
producer.flush()

first_message_timestamp = first_record_fut.result(timeout=5).timestamp()[1]
second_message_timestamp = second_record_fut.result(timeout=5).timestamp()[1]

topic_config = get_topic_configurations(admin_client, new_topic.topic, {ConfigSource.DYNAMIC_TOPIC_CONFIG})

# Execute backup creation.
Expand Down Expand Up @@ -212,7 +213,7 @@ def test_roundtrip_from_kafka_state(
# Note: This might be unreliable due to not using idempotent producer, i.e. we have
# no guarantee against duplicates currently.
assert first_record.offset() == 0
assert first_record.timestamp()[1] == 1683474641
assert first_record.timestamp()[1] == first_message_timestamp
assert first_record.timestamp()[0] == Timestamp.CREATE_TIME
assert first_record.key() == b"bar"
assert first_record.value() == b"foo"
Expand All @@ -223,7 +224,7 @@ def test_roundtrip_from_kafka_state(
assert second_record.topic() == new_topic.topic
assert second_record.partition() == partition
assert second_record.offset() == 1
assert second_record.timestamp()[1] == 1683474657
assert second_record.timestamp()[1] == second_message_timestamp
assert second_record.timestamp()[0] == Timestamp.CREATE_TIME
assert second_record.key() == b"foo"
assert second_record.value() == b"bar"
Expand Down

0 comments on commit bfc96a2

Please sign in to comment.