Skip to content

Commit a026728

Browse files
committed
Update condition to prevent race
Signed-off-by: see-quick <[email protected]>
1 parent a431892 commit a026728

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/test/java/io/strimzi/kafka/bridge/facades/AdminClientFacade.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,20 @@ public void deleteTopics(Collection<String> topics) throws InterruptedException,
9595
}
9696

9797
/**
98-
* Method hasKafkaZeroTopics used for the race condition between in-memory kafka cluster and also encapsulate the get
98+
* Wait until Kafka actually reports zero topics, or until we time out.
9999
*/
100100
public boolean hasKafkaZeroTopics() throws InterruptedException, ExecutionException {
101-
Set<String> topicSet = adminClient.listTopics().names().get();
102-
if (!topicSet.isEmpty()) {
103-
LOGGER.error("Kafka should contain 0 topics but contains {}", topicSet.toString());
104-
return false;
101+
final int maxAttempts = 5;
102+
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
103+
Set<String> topicSet = adminClient.listTopics().names().get();
104+
if (topicSet.isEmpty()) {
105+
return true;
106+
}
107+
LOGGER.warn("Topics still present on attempt {}: {}", attempt, topicSet);
108+
Thread.sleep(1000);
105109
}
106-
return true;
110+
LOGGER.error("Kafka did not report zero topics after {} attempts", maxAttempts);
111+
return false;
107112
}
108113

109114
public void close() {

0 commit comments

Comments
 (0)