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 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 @Override
public Statement apply(final Statement base, final Description description) { public Statement apply(final Statement base, final Description description) {
@ -80,18 +80,24 @@ private Statement ignoreFlakyFailure(final Statement base, final Description des
if (flakyFailuresProperty == null || !Boolean.valueOf(flakyFailuresProperty)) { if (flakyFailuresProperty == null || !Boolean.valueOf(flakyFailuresProperty)) {
return base; return base;
} }
final String flakyAttemptsProperty = System.getProperty(Flaky.FLAKY_ATTEMPTS_FAILURES_PROPERTY, "1");
final int attempts = Integer.parseInt(flakyAttemptsProperty);
return new Statement() { return new Statement() {
@Override @Override
public void evaluate() throws Throwable { public void evaluate() throws Throwable {
try { for (int i = 0; i < attempts; i++) {
base.evaluate(); try {
} base.evaluate();
catch (final Throwable t) { return;
FLAKY_LOGGER.error("Ignored failure for {}, tracked with {}", description, issueUrl(flakyClass.value()), t); }
// Marks test as skipped catch (final Throwable t) {
Assume.assumeTrue(String.format("Flaky test %s#%s failed", description.getTestClass().getSimpleName(), description.getMethodName()), false); 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 { public @interface Flaky {
String IGNORE_FLAKY_FAILURES_PROPERTY = "ignoreFlakyFailures"; String IGNORE_FLAKY_FAILURES_PROPERTY = "ignoreFlakyFailures";
String FLAKY_ATTEMPTS_FAILURES_PROPERTY = "flaky.attempts";
/** /**
* The Jira id of the issue tracking the failing test * The Jira id of the issue tracking the failing test