Add support for detecting slow test classes

Closes #46166

Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
Stian Thorgersen 2026-02-10 20:54:14 +01:00 committed by GitHub
parent 675c54f212
commit fc150d1bca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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) {