Skip to content

Commit

Permalink
Merge pull request #123 from gsmet/avoid-duplicates
Browse files Browse the repository at this point in the history
Avoid duplicates and make sure tests are sorted by name
  • Loading branch information
gsmet authored Oct 18, 2023
2 parents 52c8e9f + 80f4b13 commit 848f225
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -301,14 +303,22 @@ private Map<String, Optional<BuildReports>> downloadBuildReports(WorkflowContext
.sorted((a1, a2) -> a1.getName().compareTo(a2.getName()))
.collect(Collectors.toList());

Set<String> alreadyHandledArtifacts = new HashSet<>();

for (GHArtifact artifact : buildReportsArtifacts) {
if (alreadyHandledArtifacts.contains(artifact.getName())) {
continue;
}

Path jobDirectory = allBuildReportsDirectory.resolve(artifact.getName());

Optional<BuildReports> buildReportsOptional = buildReportsUnarchiver.getBuildReports(workflowContext,
artifact, jobDirectory);

buildReportsMap.put(artifact.getName().replace(WorkflowConstants.BUILD_REPORTS_ARTIFACT_PREFIX, ""),
buildReportsOptional);

alreadyHandledArtifacts.add(artifact.getName());
}

return buildReportsMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Path;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

Expand Down Expand Up @@ -99,6 +100,26 @@ public String getModuleName(Path jobDirectory) {
public int compareTo(TestResultsPath o) {
return path.compareTo(o.getPath());
}

@Override
public int hashCode() {
return Objects.hash(path);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SurefireTestResultsPath other = (SurefireTestResultsPath) obj;
return Objects.equals(path, other.path);
}
}

static class FailsafeTestResultsPath implements TestResultsPath {
Expand All @@ -123,6 +144,26 @@ public String getModuleName(Path jobDirectory) {
public int compareTo(TestResultsPath o) {
return path.compareTo(o.getPath());
}

@Override
public int hashCode() {
return Objects.hash(path);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
FailsafeTestResultsPath other = (FailsafeTestResultsPath) obj;
return Objects.equals(path, other.path);
}
}

static class GradleTestResultsPath implements TestResultsPath {
Expand All @@ -147,5 +188,25 @@ public String getModuleName(Path jobDirectory) {
public int compareTo(TestResultsPath o) {
return path.compareTo(o.getPath());
}

@Override
public int hashCode() {
return Objects.hash(path);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
GradleTestResultsPath other = (GradleTestResultsPath) obj;
return Objects.equals(path, other.path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Optional<BuildReports> getBuildReports(WorkflowContext workflowContext,
Awaitility.await()
.atMost(Duration.ofMinutes(5))
.pollDelay(Duration.ofSeconds(5))
.pollInterval(Duration.ofSeconds(30))
.pollInterval(Duration.ofSeconds(60))
.until(artifactIsDownloaded);
} catch (ConditionTimeoutException e) {
LOG.warn(workflowContext.getLogContext()
Expand Down Expand Up @@ -73,7 +73,7 @@ public Boolean call() {
try {
retry++;
buildReports = buildReportsArtifact
.download((is) -> unzip(is, jobDirectory));
.download((is) -> unzip(is, jobDirectory.resolve("retry-" + retry)));
return true;
} catch (Exception e) {
LOG.error(workflowContext.getLogContext() + " - Unable to download artifact "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ private List<WorkflowReportModule> getModules(
}
}

Collections.sort(workflowReportTestCases);

WorkflowReportModule module = new WorkflowReportModule(
moduleName,
moduleReports.getProjectReport(),
Expand Down Expand Up @@ -219,7 +221,7 @@ private static Map<String, ModuleReports> mapModuleReports(BuildReport buildRepo
buildReport.getProjectReports().stream().filter(pr -> normalizeModuleName(pr.getBasedir()).equals(module))
.findFirst().orElse(null),
testResultsPaths.stream().filter(trp -> normalizeModuleName(trp.getModuleName(jobDirectory)).equals(module))
.collect(Collectors.toList())));
.collect(Collectors.toCollection(TreeSet::new))));
}

return moduleReports;
Expand Down Expand Up @@ -280,9 +282,9 @@ private static String firstLines(String string, int numberOfLines) {
private static class ModuleReports {

private final ProjectReport projectReport;
private final List<TestResultsPath> testResultsPaths;
private final Set<TestResultsPath> testResultsPaths;

private ModuleReports(ProjectReport projectReport, List<TestResultsPath> testResultsPaths) {
private ModuleReports(ProjectReport projectReport, Set<TestResultsPath> testResultsPaths) {
this.projectReport = projectReport;
this.testResultsPaths = testResultsPaths;
}
Expand All @@ -291,7 +293,7 @@ public ProjectReport getProjectReport() {
return projectReport;
}

public List<TestResultsPath> getTestResultsPaths() {
public Set<TestResultsPath> getTestResultsPaths() {
return testResultsPaths;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public class WorkflowReportTestCase {
public class WorkflowReportTestCase implements Comparable<WorkflowReportTestCase> {

private final String classPath;
private final String fullName;
Expand Down Expand Up @@ -66,4 +66,24 @@ public String getFailureUrl() {
public String getShortenedFailureUrl() {
return shortenedFailureUrl;
}

@Override
public int compareTo(WorkflowReportTestCase o) {
int compare = this.fullName.compareTo(o.fullName);

if (compare != 0 ||
this.failureErrorLine == null || this.failureErrorLine.isBlank() ||
o.failureErrorLine == null || o.failureErrorLine.isBlank()) {
return compare;
}

try {
Integer thisLine = Integer.valueOf(this.failureErrorLine);
Integer otherLine = Integer.valueOf(o.failureErrorLine);

return thisLine.compareTo(otherLine);
} catch (NumberFormatException e) {
return compare;
}
}
}

0 comments on commit 848f225

Please sign in to comment.