Skip to content

Commit e041e3b

Browse files
committed
Improve flaky test reporting
1 parent 6daa5ff commit e041e3b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

+29
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;
@@ -80,6 +87,28 @@ private void scanTestFile(Path testReport) {
8087
return;
8188
}
8289

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

0 commit comments

Comments
 (0)