Skip to content

Commit

Permalink
RATIS-2217. Automatically re-try flaky tests in CI (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Feb 26, 2025
1 parent 6238fe3 commit e604110
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
- grpc
- server
- misc
- flaky
fail-fast: false
uses: ./.github/workflows/check.yaml
with:
Expand Down
4 changes: 4 additions & 0 deletions dev-support/checks/unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ mkdir -p "$REPORT_DIR"
export MAVEN_OPTS="-Xmx4096m"
MAVEN_OPTIONS='-V -B'

if [[ "$@" =~ "-Pflaky-tests" ]]; then
MAVEN_OPTIONS="${MAVEN_OPTIONS} -Dsurefire.rerunFailingTestsCount=5 -Dsurefire.timeout=1200"
fi

if [[ "${FAIL_FAST}" == "true" ]]; then
MAVEN_OPTIONS="${MAVEN_OPTIONS} --fail-fast -Dsurefire.skipAfterFailureCount=1"
else
Expand Down
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
<slf4j.version>2.0.7</slf4j.version>
<junit-bom.version>5.11.2</junit-bom.version>
<jacoco.version>0.8.12</jacoco.version>
<flaky-test-groups>flaky | org.apache.ratis.test.tag.FlakyTest</flaky-test-groups>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -1118,6 +1119,7 @@
<includes>
<include>org.apache.ratis.grpc.**</include>
</includes>
<excludedGroups>${flaky-test-groups}</excludedGroups>
</configuration>
</plugin>
</plugins>
Expand All @@ -1135,6 +1137,7 @@
<include>org.apache.ratis.datastream.**</include>
<include>org.apache.ratis.server.**</include>
</includes>
<excludedGroups>${flaky-test-groups}</excludedGroups>
</configuration>
</plugin>
</plugins>
Expand All @@ -1153,6 +1156,21 @@
<exclude>org.apache.ratis.grpc.**</exclude>
<exclude>org.apache.ratis.server.**</exclude>
</excludes>
<excludedGroups>${flaky-test-groups}</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>flaky-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${flaky-test-groups}</groups>
</configuration>
</plugin>
</plugins>
Expand Down
2 changes: 2 additions & 0 deletions ratis-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<test.cache.data>${project.build.directory}/test-classes</test.cache.data>
<test.build.classes>${project.build.directory}/test-classes</test.build.classes>
<license.bundles.dependencies>true</license.bundles.dependencies>
<!-- no testable code in this module -->
<skipTests>true</skipTests>
</properties>

<build>
Expand Down
5 changes: 5 additions & 0 deletions ratis-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-client</artifactId>
<name>Apache Ratis Client</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.ratis</groupId>
Expand Down
41 changes: 41 additions & 0 deletions ratis-common/src/test/java/org/apache/ratis/test/tag/Flaky.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ratis.test.tag;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.Tag;

/**
* Annotation to mark JUnit5 test classes or methods that exhibit intermittent
* issues. These are run separately from the normal tests in CI. In case of
* failure they may be repeated a few times.
* Usage: <code>@Flaky("RATIS-123")</code>
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Tag("flaky")
public @interface Flaky {
/**
* The issue(s) tracking the flaky test.
*/
String[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ratis.test.tag;

/**
* Interface to mark JUnit4 test classes or methods that exhibit intermittent
* issues. These are run separately from the normal tests in CI. In case of
* failure they may be repeated a few times.
* Usage: <code>@Category(FlakyTest.class) @Flaky("RATIS-123")</code>
*/
public interface FlakyTest {
// category marker
}
6 changes: 6 additions & 0 deletions ratis-docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>ratis-docs</artifactId>
<name>Apache Ratis Documentation</name>
<packaging>jar</packaging>

<properties>
<!-- no testable code in this module -->
<skipTests>true</skipTests>
</properties>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.ratis.protocol.RaftGroup;
import org.apache.ratis.server.impl.GroupManagementBaseTest;
import org.apache.ratis.server.impl.MiniRaftCluster;
import org.apache.ratis.test.tag.Flaky;
import org.apache.ratis.util.function.CheckedBiConsumer;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -33,6 +34,7 @@
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;

@Flaky("RATIS-2218")
@Timeout(value = 300)
public class TestMultiRaftGroup extends BaseTest {
public static Collection<Object[]> data() {
Expand Down
5 changes: 5 additions & 0 deletions ratis-experiments/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-experiments</artifactId>
<name>Apache Ratis Experiments</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.ratis</groupId>
Expand Down
5 changes: 5 additions & 0 deletions ratis-metrics-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<artifactId>ratis-metrics-api</artifactId>
<name>Apache Ratis Metrics API</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<artifactId>ratis-common</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions ratis-netty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-netty</artifactId>
<name>Apache Ratis Netty Support</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.ratis</groupId>
Expand Down
2 changes: 2 additions & 0 deletions ratis-proto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<!-- no testable code in this module -->
<skipTests>true</skipTests>
<spotbugs.skip>true</spotbugs.skip>
</properties>

Expand Down
5 changes: 5 additions & 0 deletions ratis-replicated-map/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-replicated-map</artifactId>
<name>Apache Ratis Replicated Map</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.ratis</groupId>
Expand Down
5 changes: 5 additions & 0 deletions ratis-server-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-server-api</artifactId>
<name>Apache Ratis Server API</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.ratis</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.ratis.server.RaftServerConfigKeys;
import org.apache.ratis.server.metrics.LeaderElectionMetrics;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.ratis.test.tag.Flaky;
import org.apache.ratis.thirdparty.com.codahale.metrics.Timer;
import org.apache.ratis.util.CodeInjectionForTesting;
import org.apache.ratis.util.JavaUtils;
Expand Down Expand Up @@ -729,6 +730,7 @@ void runTestLeaderLease(CLUSTER cluster, long leaseTimeoutMs) throws Exception {
}
}

@Flaky("RATIS-2108")
@Test
public void testLeaderLeaseDuringReconfiguration() throws Exception {
// use a strict lease
Expand Down
5 changes: 5 additions & 0 deletions ratis-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-shell</artifactId>
<name>Apache Ratis Shell</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<artifactId>ratis-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.ratis.server.raftlog.RaftLog;
import org.apache.ratis.statemachine.impl.SimpleStateMachine4Testing;
import org.apache.ratis.statemachine.StateMachine;
import org.apache.ratis.test.tag.Flaky;
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.TimeDuration;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -55,6 +56,7 @@ public void testWithLoad() {
// skip testWithLoad() from parent, called from parameterized testWithLoad(boolean)
}

@Flaky("RATIS-2253")
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testWithLoad(boolean separateHeartbeat) throws Exception {
Expand Down
5 changes: 5 additions & 0 deletions ratis-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>ratis-tools</artifactId>
<name>Apache Ratis Tools</name>

<properties>
<!-- no tests in this module so far -->
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.ratis</groupId>
Expand Down

0 comments on commit e604110

Please sign in to comment.