mirror of
https://github.com/keycloak/keycloak.git
synced 2026-06-04 14:26:19 -04:00
Add support for detecting slow test classes
Closes #46166 Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
parent
675c54f212
commit
fc150d1bca
3 changed files with 29 additions and 2 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
|
@ -12,7 +12,8 @@ env:
|
|||
MAVEN_ARGS: "-B -nsu -Daether.connector.http.connectionMaxTtl=25"
|
||||
SUREFIRE_RERUN_FAILING_COUNT: 2
|
||||
SUREFIRE_RETRY: "-Dsurefire.rerunFailingTestsCount=2"
|
||||
KC_TEST_GITHUB_SLOW: "10"
|
||||
KC_TEST_GITHUB_SLOW_METHOD: "10"
|
||||
KC_TEST_GITHUB_SLOW_CLASS: "60"
|
||||
|
||||
concurrency:
|
||||
# Only cancel jobs for PR updates
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public class LogHandler implements AutoCloseable {
|
|||
public void beforeAll(ExtensionContext context) {
|
||||
logDivider(Logger.Level.INFO);
|
||||
logTestClassStatus(context, Status.RUNNING, Logger.Level.INFO);
|
||||
gitHubActionReport.onClassStart();
|
||||
}
|
||||
|
||||
public void beforeEachStarting(ExtensionContext context) {
|
||||
|
|
@ -60,6 +61,8 @@ public class LogHandler implements AutoCloseable {
|
|||
Status status = context.getExecutionException().isPresent() ? Status.FAILED : Status.SUCCESS;
|
||||
if (status == Status.FAILED) {
|
||||
gitHubActionReport.onClassError(context);
|
||||
} else {
|
||||
gitHubActionReport.onClassSuccess(context);
|
||||
}
|
||||
logTestClassStatus(context, status, Logger.Level.DEBUG);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ public class GitHubActionReport {
|
|||
private final File gitHubStepSummary;
|
||||
private final String gitRoot = findGitRoot();
|
||||
|
||||
private final long slowTestClassTimeout;
|
||||
private final long slowTestTimeout;
|
||||
|
||||
private long testClassStartedAt;
|
||||
private long testStartedAt;
|
||||
|
||||
private List<Failure> failures = new LinkedList<>();
|
||||
|
|
@ -36,7 +38,28 @@ public class GitHubActionReport {
|
|||
public GitHubActionReport() {
|
||||
this.gitHubStepSummary = GITHUB_STEP_SUMMARY != null ? new File(GITHUB_STEP_SUMMARY) : null;
|
||||
this.enabled = Config.get("kc.test.github.enabled", true, Boolean.class) && gitHubStepSummary != null;
|
||||
this.slowTestTimeout = TimeUnit.SECONDS.toMillis(Config.get("kc.test.github.slow", 30L, Long.class));
|
||||
this.slowTestClassTimeout = TimeUnit.SECONDS.toMillis(Config.get("kc.test.github.slow.class", 120L, Long.class));
|
||||
this.slowTestTimeout = TimeUnit.SECONDS.toMillis(Config.get("kc.test.github.slow.method", 30L, Long.class));
|
||||
}
|
||||
|
||||
public void onClassStart() {
|
||||
if (enabled) {
|
||||
testClassStartedAt = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public void onClassSuccess(ExtensionContext context) {
|
||||
if (enabled) {
|
||||
if (slowTestClassTimeout >= -1) {
|
||||
long executionTime = System.currentTimeMillis() - testClassStartedAt;
|
||||
if (executionTime > slowTestClassTimeout) {
|
||||
Class<?> testClass = context.getRequiredTestClass();
|
||||
String file = findJavaClass(testClass);
|
||||
String link = getLink(file, -1);
|
||||
slowTests.add(new Slow(context.getRequiredTestClass().getName(), "", executionTime, link));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onClassError(ExtensionContext context) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue