fix flaky testTransactionMetaStoreAssignAndFailover
Replaced check after sleep to `untilAsserted` and extended `atMost` time to 10 seconds(default of `Awaitility`) which can reduce the fail rate
*/
package org.apache.pulsar.broker.transaction.coordinator;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.pulsar.broker.PulsarService;
+import org.awaitility.Awaitility;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
public class TransactionMetaStoreAssignmentTest extends TransactionMetaStoreTestBase {
@BeforeClass
@@ -65,14 +65,17 @@ public class TransactionMetaStoreAssignmentTest extends TransactionMetaStoreTest
}
crashedMetaStore.close();
- Thread.sleep(3000);
+ Awaitility.await()
+ .untilAsserted(() -> {
- transactionMetaStoreCount = 0;
+ int transactionMetaStoreCount2 = 0;
for (PulsarService pulsarService : pulsarServices) {
- transactionMetaStoreCount += pulsarService.getTransactionMetadataStoreService().getStores().size();
+ transactionMetaStoreCount2 += pulsarService.getTransactionMetadataStoreService().getStores()
+ .size();
}
- Assert.assertEquals(transactionMetaStoreCount, 16);
+ Assert.assertEquals(transactionMetaStoreCount2, 16);
+ });
transactionCoordinatorClient.close();
}
