Skip to content

Commit d18f429

Browse files
lhotarisrinath-ctds
authored andcommitted
[improve][test] Move most flaky tests to flaky group (apache#22433)
- also add solution for running test methods added to flaky group since that was missing (cherry picked from commit 5f31ec3) # Conflicts: # pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicAuthZTest.java # pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TransactionEndToEndTest.java (cherry picked from commit 097805d)
1 parent 7ab68ca commit d18f429

File tree

10 files changed

+46
-16
lines changed

10 files changed

+46
-16
lines changed

build/run_unit_group.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,21 @@ function print_testng_failures() {
135135
function test_group_broker_flaky() {
136136
echo "::endgroup::"
137137
echo "::group::Running quarantined tests"
138-
mvn_test --no-fail-fast -pl pulsar-broker -Dgroups='quarantine' -DexcludedGroups='' -DfailIfNoTests=false \
138+
mvn_test --no-fail-fast -pl pulsar-broker -Dgroups='quarantine' -DexcludedGroups='flaky' -DfailIfNoTests=false \
139139
-DtestForkCount=2 ||
140140
print_testng_failures pulsar-broker/target/surefire-reports/testng-failed.xml "Quarantined test failure in" "Quarantined test failures"
141141
echo "::endgroup::"
142142
echo "::group::Running flaky tests"
143-
mvn_test --no-fail-fast -pl pulsar-broker -Dgroups='flaky' -DtestForkCount=2
143+
mvn_test --no-fail-fast -pl pulsar-broker -Dgroups='flaky' -DexcludedGroups='quarantine' -DtestForkCount=2
144144
echo "::endgroup::"
145+
local modules_with_flaky_tests=$(git grep -l '@Test.*"flaky"' | grep '/src/test/java/' | \
146+
awk -F '/src/test/java/' '{ print $1 }' | grep -v -E 'pulsar-broker' | sort | uniq | \
147+
perl -0777 -p -e 's/\n(\S)/,$1/g')
148+
if [ -n "${modules_with_flaky_tests}" ]; then
149+
echo "::group::Running flaky tests in modules '${modules_with_flaky_tests}'"
150+
mvn_test --no-fail-fast -pl "${modules_with_flaky_tests}" -Dgroups='flaky' -DexcludedGroups='quarantine' -DfailIfNoTests=false
151+
echo "::endgroup::"
152+
fi
145153
}
146154

147155
function test_group_proxy() {
@@ -175,7 +183,7 @@ function test_group_other() {
175183
perl -0777 -p -e 's/\n(\S)/,$1/g')
176184
if [ -n "${modules_with_quarantined_tests}" ]; then
177185
echo "::group::Running quarantined tests outside of pulsar-broker & pulsar-proxy (if any)"
178-
mvn_test --no-fail-fast -pl "${modules_with_quarantined_tests}" test -Dgroups='quarantine' -DexcludedGroups='' \
186+
mvn_test --no-fail-fast -pl "${modules_with_quarantined_tests}" test -Dgroups='quarantine' -DexcludedGroups='flaky' \
179187
-DfailIfNoTests=false || \
180188
echo "::warning::There were test failures in the 'quarantine' test group."
181189
echo "::endgroup::"

buildtools/src/main/java/org/apache/pulsar/tests/AnnotationListener.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class AnnotationListener implements IAnnotationTransformer {
3232
private static final long DEFAULT_TEST_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(5);
3333
private static final String OTHER_GROUP = "other";
3434

35+
private static final String FLAKY_GROUP = "flaky";
36+
37+
private static final String QUARANTINE_GROUP = "quarantine";
38+
3539
public AnnotationListener() {
3640
System.out.println("Created annotation listener");
3741
}
@@ -51,9 +55,27 @@ public void transform(ITestAnnotation annotation,
5155
annotation.setTimeOut(DEFAULT_TEST_TIMEOUT_MILLIS);
5256
}
5357

58+
replaceGroupsIfFlakyOrQuarantineGroupIsIncluded(annotation);
5459
addToOtherGroupIfNoGroupsSpecified(annotation);
5560
}
5661

62+
// A test method will inherit the test groups from the class level and this solution ensures that a test method
63+
// added to the flaky or quarantine group will not be executed as part of other groups.
64+
private void replaceGroupsIfFlakyOrQuarantineGroupIsIncluded(ITestAnnotation annotation) {
65+
if (annotation.getGroups() != null && annotation.getGroups().length > 1) {
66+
for (String group : annotation.getGroups()) {
67+
if (group.equals(QUARANTINE_GROUP)) {
68+
annotation.setGroups(new String[]{QUARANTINE_GROUP});
69+
return;
70+
}
71+
if (group.equals(FLAKY_GROUP)) {
72+
annotation.setGroups(new String[]{FLAKY_GROUP});
73+
return;
74+
}
75+
}
76+
}
77+
}
78+
5779
private void addToOtherGroupIfNoGroupsSpecified(ITestOrConfiguration annotation) {
5880
// Add test to "other" group if there's no specified group
5981
if (annotation.getGroups() == null || annotation.getGroups().length == 0) {

managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ public void testRetentionSize() throws Exception {
24402440
});
24412441
}
24422442

2443-
@Test
2443+
@Test(groups = "flaky")
24442444
public void testTimestampOnWorkingLedger() throws Exception {
24452445
ManagedLedgerConfig conf = new ManagedLedgerConfig();
24462446
conf.setMaxEntriesPerLedger(1);
@@ -3505,7 +3505,7 @@ public void testLedgerReachMaximumRolloverTime() throws Exception {
35053505
.until(() -> firstLedgerId != ml.addEntry("test".getBytes()).getLedgerId());
35063506
}
35073507

3508-
@Test
3508+
@Test(groups = "flaky")
35093509
public void testLedgerNotRolloverWithoutOpenState() throws Exception {
35103510
ManagedLedgerConfig config = new ManagedLedgerConfig();
35113511
config.setMaxEntriesPerLedger(2);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ flexible messaging model and an intuitive client API.</description>
8888
<include>**/Test*.java,**/*Test.java,**/*Tests.java,**/*TestCase.java</include>
8989
<exclude/>
9090
<groups/>
91-
<excludedGroups>quarantine</excludedGroups>
91+
<excludedGroups>quarantine,flaky</excludedGroups>
9292

9393
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
9494
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiMultiBrokersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void testTopicLookup(TopicDomain topicDomain, boolean isPartition) throws
132132
Assert.assertEquals(lookupResultSet.size(), 1);
133133
}
134134

135-
@Test
135+
@Test(groups = "flaky")
136136
public void testForceDeletePartitionedTopicWithSub() throws Exception {
137137
final int numPartitions = 10;
138138
TenantInfoImpl tenantInfo = new TenantInfoImpl(Set.of("role1", "role2"), Set.of("test"));

pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicAuthZTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class TopicAuthZTest extends MockedPulsarStandalone {
5353
.claim("sub", TENANT_ADMIN_SUBJECT).signWith(SECRET_KEY).compact();
5454

5555
@SneakyThrows
56-
@BeforeClass
56+
@BeforeClass(alwaysRun = true)
5757
public void before() {
5858
configureTokenAuthentication();
5959
configureDefaultAuthorization();
@@ -73,7 +73,7 @@ public void before() {
7373

7474

7575
@SneakyThrows
76-
@AfterClass
76+
@AfterClass(alwaysRun = true)
7777
public void after() {
7878
if (superUserAdmin != null) {
7979
superUserAdmin.close();

pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PersistentMessageFinderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void testPersistentMessageFinderWhenLastMessageDelete() throws Exception {
266266
ledger.addEntry(createMessageWrittenToLedger("msg2"));
267267
ledger.addEntry(createMessageWrittenToLedger("msg3"));
268268
Position lastPosition = ledger.addEntry(createMessageWrittenToLedger("last-message"));
269-
269+
270270
long endTimestamp = System.currentTimeMillis() + 1000;
271271

272272
Result result = new Result();
@@ -383,7 +383,7 @@ public static Set<BrokerEntryMetadataInterceptor> getBrokerEntryMetadataIntercep
383383
*
384384
* @throws Exception
385385
*/
386-
@Test
386+
@Test(groups = "flaky")
387387
void testMessageExpiryWithTimestampNonRecoverableException() throws Exception {
388388

389389
final String ledgerAndCursorName = "testPersistentMessageExpiryWithNonRecoverableLedgers";
@@ -440,7 +440,7 @@ void testMessageExpiryWithTimestampNonRecoverableException() throws Exception {
440440

441441
}
442442

443-
@Test
443+
@Test(groups = "flaky")
444444
public void testIncorrectClientClock() throws Exception {
445445
final String ledgerAndCursorName = "testIncorrectClientClock";
446446
int maxTTLSeconds = 1;

pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerConsumerInternalTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private void removeServiceProducerMaintainedByServerCnx(ServiceProducer serviceP
116116
});
117117
}
118118

119-
@Test
119+
@Test(groups = "flaky")
120120
public void testExclusiveConsumerWillAlwaysRetryEvenIfReceivedConsumerBusyError() throws Exception {
121121
final String topicName = BrokerTestUtil.newUniqueName("persistent://my-property/my-ns/tp_");
122122
final String subscriptionName = "subscription1";

pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TransactionEndToEndTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class TransactionEndToEndTest extends TransactionTestBase {
9696
protected static final String TOPIC_OUTPUT = NAMESPACE1 + "/output";
9797
protected static final String TOPIC_MESSAGE_ACK_TEST = NAMESPACE1 + "/message-ack-test";
9898
protected static final int NUM_PARTITIONS = 16;
99-
@BeforeClass
99+
@BeforeClass(alwaysRun = true)
100100
protected void setup() throws Exception {
101101
conf.setAcknowledgmentAtBatchIndexLevelEnabled(true);
102102
setUpBase(1, NUM_PARTITIONS, TOPIC_OUTPUT, TOPIC_PARTITION);
@@ -1624,7 +1624,7 @@ public void testSendTxnAckBatchMessageToDLQ() throws Exception {
16241624
admin.topics().delete(topic, true);
16251625
}
16261626

1627-
@Test
1627+
@Test(groups = "flaky")
16281628
public void testDelayedTransactionMessages() throws Exception {
16291629
String topic = NAMESPACE1 + "/testDelayedTransactionMessages";
16301630

pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TransactionEndToEndWithoutBatchIndexAckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@Test(groups = "broker-impl")
3131
public class TransactionEndToEndWithoutBatchIndexAckTest extends TransactionEndToEndTest {
3232

33-
@BeforeClass
33+
@BeforeClass(alwaysRun = true)
3434
protected void setup() throws Exception {
3535
conf.setAcknowledgmentAtBatchIndexLevelEnabled(false);
3636
setUpBase(1, NUM_PARTITIONS, TOPIC_OUTPUT, TOPIC_PARTITION);

0 commit comments

Comments
 (0)