From f7c2e01aaf3f9860034ad6aef7fbf6100b151b41 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 12 Mar 2024 10:46:33 +0100 Subject: [PATCH 1/2] Make sure there are no duplicate cases This can happen if the same test case (class name + method name) appears in multiple branches of the same build. For example, this happens for InjectedTest, which is set in the root package for any jenkins plugin --- .../testmode/JavaClassName.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/parallel_test_executor/testmode/JavaClassName.java b/src/main/java/org/jenkinsci/plugins/parallel_test_executor/testmode/JavaClassName.java index ba701819..3e24cb37 100644 --- a/src/main/java/org/jenkinsci/plugins/parallel_test_executor/testmode/JavaClassName.java +++ b/src/main/java/org/jenkinsci/plugins/parallel_test_executor/testmode/JavaClassName.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,7 +52,7 @@ public boolean isSplitByCase() { @NonNull public Map getTestEntitiesMap(@NonNull ClassResult classResult) { if (isSplitByCase()) { - return classResult.getChildren().stream().map(JavaTestCase::new).collect(Collectors.toMap(JavaTestCase::getKey, identity())); + return classResult.getChildren().stream().map(JavaTestCase::new).distinct().collect(Collectors.toMap(JavaTestCase::getKey, identity())); } else { TestClass testClass = new TestClass(classResult); return Map.of(testClass.getKey(), testClass); @@ -108,6 +109,19 @@ public List getElements() { public String toString() { return output; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + JavaTestCase that = (JavaTestCase) o; + return Objects.equals(output, that.output); + } + + @Override + public int hashCode() { + return Objects.hash(output); + } } @Extension From bbf81f4ec048aab8fe41de44041df5a34c7572ec Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Tue, 12 Mar 2024 12:47:35 +0100 Subject: [PATCH 2/2] add test --- .../ParallelTestExecutorUnitTest.java | 5 ++++ .../findTestDuplicates/report-Test1-bis.xml | 23 +++++++++++++++++++ .../findTestDuplicates/report-Test1.xml | 23 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1-bis.xml create mode 100644 src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1.xml diff --git a/src/test/java/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest.java b/src/test/java/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest.java index 56b4b78f..1fe13193 100644 --- a/src/test/java/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest.java +++ b/src/test/java/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest.java @@ -95,6 +95,11 @@ public void findTestSplits() throws Exception { // Splitting by test cases we can parallelize more! checkTestSplits(new CountDrivenParallelism(10), 10, new JavaTestCaseName()); } + + @Test + public void findTestDuplicates() throws Exception { + checkTestSplits(new CountDrivenParallelism(10), 10, new JavaTestCaseName()); + } @Test public void findTestCaseTimeSplitsExclusion() throws Exception { diff --git a/src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1-bis.xml b/src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1-bis.xml new file mode 100644 index 00000000..3cc315aa --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1-bis.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1.xml b/src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1.xml new file mode 100644 index 00000000..3cc315aa --- /dev/null +++ b/src/test/resources/org/jenkinsci/plugins/parallel_test_executor/ParallelTestExecutorUnitTest/findTestDuplicates/report-Test1.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file