Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flaky test reporting #13477

Merged
merged 3 commits into from
Mar 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -64,6 +71,7 @@ private static Document parse(Path testReport) {
}
}

@SuppressWarnings("JavaTimeDefaultTimeZone")
private void scanTestFile(Path testReport) {
Document doc = parse(testReport);
doc.getDocumentElement().normalize();
Expand All @@ -80,6 +88,29 @@ private void scanTestFile(Path testReport) {
return;
}

// google sheets don't automatically recognize dates with time zone, here we reformat the date
// so that it wouldn't have the time zone
TemporalAccessor ta =
DateTimeFormatter.ISO_DATE_TIME.parseBest(
timestamp, ZonedDateTime::from, LocalDateTime::from);
timestamp = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(ta);

// when test result file was modified more than 20 minutes after the time in the results file
// then the test results were restored from gradle cache and the test wasn't actually executed
Instant reportModified = Instant.ofEpochMilli(testReport.toFile().lastModified());
reportModified = reportModified.minus(20, ChronoUnit.MINUTES);
Instant testExecuted = null;
if (ta instanceof ZonedDateTime) {
testExecuted = ((ZonedDateTime) ta).toInstant();
} else if (ta instanceof LocalDateTime) {
testExecuted = ((LocalDateTime) ta).toInstant(OffsetDateTime.now().getOffset());
}
if (testExecuted != null && reportModified.isAfter(testExecuted)) {
System.err.println(
"Ignoring " + testReport + " since it appears to be restored from gradle build cache");
return;
}

class TestCase {
final String className;
final String name;
Expand Down
Loading