Skip to content

Commit 9b42cf5

Browse files
authored
tests/kafka: silence errors arounds create and delete topics (#2237)
Use a big hammer in the meantime we find a proper solution and catch all exceptions.
1 parent a15ec54 commit 9b42cf5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/instrumentation/kafka_tests.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@
5454
def topics():
5555
topics = ["test", "foo", "bar"]
5656
admin_client = KafkaAdminClient(bootstrap_servers=[f"{KAFKA_HOST}:9092"])
57-
admin_client.create_topics([NewTopic(name, num_partitions=1, replication_factor=1) for name in topics])
57+
# since kafka-python 2.1.0 we started to get failures in create_topics because topics were already there despite
58+
# calls to delete_topics. In the meantime we found a proper fix use a big hammer and catch topics handling failures
59+
# https://github.com/dpkp/kafka-python/issues/2557
60+
try:
61+
admin_client.create_topics([NewTopic(name, num_partitions=1, replication_factor=1) for name in topics])
62+
except Exception:
63+
pass
5864
yield topics
59-
admin_client.delete_topics(topics)
65+
try:
66+
admin_client.delete_topics(topics)
67+
except Exception:
68+
pass
6069

6170

6271
@pytest.fixture()

0 commit comments

Comments
 (0)