Skip to content

Commit 93be949

Browse files
authored
Improve flaky test reporting (#13477)
1 parent c7676bd commit 93be949

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test-report/src/main/java/io/opentelemetry/instrumentation/testreport/FlakyTestReporter.java

+31
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
import java.nio.file.Path;
2525
import java.nio.file.SimpleFileVisitor;
2626
import java.nio.file.attribute.BasicFileAttributes;
27+
import java.time.Instant;
28+
import java.time.LocalDateTime;
29+
import java.time.OffsetDateTime;
30+
import java.time.ZonedDateTime;
31+
import java.time.format.DateTimeFormatter;
32+
import java.time.temporal.ChronoUnit;
33+
import java.time.temporal.TemporalAccessor;
2734
import java.util.ArrayList;
2835
import java.util.Collections;
2936
import java.util.HashMap;
@@ -64,6 +71,7 @@ private static Document parse(Path testReport) {
6471
}
6572
}
6673

74+
@SuppressWarnings("JavaTimeDefaultTimeZone")
6775
private void scanTestFile(Path testReport) {
6876
Document doc = parse(testReport);
6977
doc.getDocumentElement().normalize();
@@ -80,6 +88,29 @@ private void scanTestFile(Path testReport) {
8088
return;
8189
}
8290

91+
// google sheets don't automatically recognize dates with time zone, here we reformat the date
92+
// so that it wouldn't have the time zone
93+
TemporalAccessor ta =
94+
DateTimeFormatter.ISO_DATE_TIME.parseBest(
95+
timestamp, ZonedDateTime::from, LocalDateTime::from);
96+
timestamp = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(ta);
97+
98+
// when test result file was modified more than 20 minutes after the time in the results file
99+
// then the test results were restored from gradle cache and the test wasn't actually executed
100+
Instant reportModified = Instant.ofEpochMilli(testReport.toFile().lastModified());
101+
reportModified = reportModified.minus(20, ChronoUnit.MINUTES);
102+
Instant testExecuted = null;
103+
if (ta instanceof ZonedDateTime) {
104+
testExecuted = ((ZonedDateTime) ta).toInstant();
105+
} else if (ta instanceof LocalDateTime) {
106+
testExecuted = ((LocalDateTime) ta).toInstant(OffsetDateTime.now().getOffset());
107+
}
108+
if (testExecuted != null && reportModified.isAfter(testExecuted)) {
109+
System.err.println(
110+
"Ignoring " + testReport + " since it appears to be restored from gradle build cache");
111+
return;
112+
}
113+
83114
class TestCase {
84115
final String className;
85116
final String name;

0 commit comments

Comments
 (0)