dajac commented on a change in pull request #11681:
URL: https://github.com/apache/kafka/pull/11681#discussion_r800041619



##########
File path: core/src/test/scala/unit/kafka/admin/LeaderElectionCommandTest.scala
##########
@@ -55,9 +54,18 @@ final class LeaderElectionCommandTest(cluster: 
ClusterInstance) {
     
clusterConfig.serverProperties().put(KafkaConfig.OffsetsTopicReplicationFactorProp,
 "2")
   }
 
+  def waitForAdminClientHaveNumBrokers(numBrokers: Int): Admin = {
+    // Use a temporary adminClient to wait for all brokers up
+    // If we don't wait for the brokers up, we might have race condition that 
the metadata in adminClient only has broker2 or broker3 up,
+    // and after broker2/broker3 shutdown, no brokers are available to 
connect, which causes request timeout
+    TestUtils.waitForNumNodesUp(cluster.createAdminClient(), numBrokers)
+
+    cluster.createAdminClient()
+  }
+
   @ClusterTest
   def testAllTopicPartition(): Unit = {
-    val client = cluster.createAdminClient()
+    val client = waitForAdminClientHaveNumBrokers(3)

Review comment:
       At L73, there is `cluster.waitForReadyBrokers()` which wait until the 
cluster is ready. Would it make sense to move the creating of the admin client 
after that in all tests?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to