DBZ-6324 Add retry for flaking tests

This commit is contained in:
Jiri Pechanec 2023-04-12 12:04:38 +02:00
parent f64c35de29
commit ab66f038e4
2 changed files with 15 additions and 8 deletions

View File

@ -26,7 +26,7 @@ public class ConditionalFail extends AnnotationBasedTestRule {
private static final Logger FLAKY_LOGGER = LoggerFactory.getLogger(Flaky.class);
private static final String JIRA_BASE_URL = "https://issues.jboss.org/browse/";
private static final String JIRA_BASE_URL = "https://issues.redhat.com/browse/";
@Override
public Statement apply(final Statement base, final Description description) {
@ -80,19 +80,25 @@ private Statement ignoreFlakyFailure(final Statement base, final Description des
if (flakyFailuresProperty == null || !Boolean.valueOf(flakyFailuresProperty)) {
return base;
}
final String flakyAttemptsProperty = System.getProperty(Flaky.FLAKY_ATTEMPTS_FAILURES_PROPERTY, "1");
final int attempts = Integer.parseInt(flakyAttemptsProperty);
return new Statement() {
@Override
public void evaluate() throws Throwable {
for (int i = 0; i < attempts; i++) {
try {
base.evaluate();
return;
}
catch (final Throwable t) {
FLAKY_LOGGER.error("Ignored failure for {}, tracked with {}", description, issueUrl(flakyClass.value()), t);
}
}
// Marks test as skipped
Assume.assumeTrue(String.format("Flaky test %s#%s failed", description.getTestClass().getSimpleName(), description.getMethodName()), false);
}
}
};
}

View File

@ -21,6 +21,7 @@
public @interface Flaky {
String IGNORE_FLAKY_FAILURES_PROPERTY = "ignoreFlakyFailures";
String FLAKY_ATTEMPTS_FAILURES_PROPERTY = "flaky.attempts";
/**
* The Jira id of the issue tracking the failing test