Skip to content

Commit 3a90162

Browse files
khnealtimja
andauthored
JENKINS-48583 Remove test result deduplication logic (#131)
Co-authored-by: Kevin Neal <[email protected]> Co-authored-by: Tim Jacomb <[email protected]>
1 parent 67e9ddb commit 3a90162

File tree

6 files changed

+79
-24
lines changed

6 files changed

+79
-24
lines changed

src/main/java/hudson/tasks/junit/TestResult.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,10 @@ private void add(SuiteResult sr) {
286286
for (SuiteResult s : suites) {
287287
// JENKINS-12457: If a testsuite is distributed over multiple files, merge it into a single SuiteResult:
288288
if(s.getName().equals(sr.getName()) &&
289-
nullSafeEq(s.getId(),sr.getId()) &&
289+
eitherNullOrEq(s.getId(),sr.getId()) &&
290290
nullSafeEq(s.getNodeId(),sr.getNodeId()) &&
291291
nullSafeEq(s.getEnclosingBlocks(),sr.getEnclosingBlocks()) &&
292292
nullSafeEq(s.getEnclosingBlockNames(),sr.getEnclosingBlockNames())) {
293-
294-
// However, a common problem is that people parse TEST-*.xml as well as TESTS-TestSuite.xml.
295-
// In that case consider the result file as a duplicate and discard it.
296-
// see http://jenkins.361315.n4.nabble.com/Problem-with-duplicate-build-execution-td371616.html for discussion.
297-
if(strictEq(s.getTimestamp(),sr.getTimestamp())) {
298-
return;
299-
}
300293

301294
duration += sr.getDuration();
302295
s.merge(sr);
@@ -330,6 +323,13 @@ private boolean nullSafeEq(Object lhs, Object rhs) {
330323
return lhs.equals(rhs);
331324
}
332325

326+
private boolean eitherNullOrEq(Object lhs, Object rhs) {
327+
// Merged testSuites may have attribute (ID) not preset in the original.
328+
// If both have an ID, compare it.
329+
// If either does not have an ID, then assume they are the same.
330+
return lhs == null || rhs == null || lhs.equals(rhs);
331+
}
332+
333333
@Deprecated
334334
public void parse(File reportFile) throws IOException {
335335
parse(reportFile, null);

src/test/java/hudson/tasks/junit/TestResultTest.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public void testDuplicateTestMethods() throws IOException, URISyntaxException {
136136
assertEquals("Wrong number of test cases", 3, testResult.getTotalCount());
137137
}
138138

139-
@Bug(12457)
139+
@Issue("JENKINS-12457")
140+
@Test
140141
public void testTestSuiteDistributedOverMultipleFilesIsCountedAsOne() throws IOException, URISyntaxException {
141142
TestResult testResult = new TestResult();
142143
testResult.parse(getDataFile("JENKINS-12457/TestSuite_a1.xml"), null);
@@ -149,21 +150,6 @@ public void testTestSuiteDistributedOverMultipleFilesIsCountedAsOne() throws IOE
149150
// check duration: 157.980 (TestSuite_a1.xml) and 15.000 (TestSuite_a2.xml) = 172.98
150151
assertEquals("Wrong duration for test result", 172.98, testResult.getDuration(), 0.1);
151152
}
152-
153-
/**
154-
* A common problem is that people parse TEST-*.xml as well as TESTS-TestSuite.xml.
155-
* See http://jenkins.361315.n4.nabble.com/Problem-with-duplicate-build-execution-td371616.html for discussion.
156-
*/
157-
public void testDuplicatedTestSuiteIsNotCounted() throws IOException, URISyntaxException {
158-
TestResult testResult = new TestResult();
159-
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b.xml"), null);
160-
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b_duplicate.xml"), null);
161-
testResult.tally();
162-
163-
assertEquals("Wrong number of testsuites", 1, testResult.getSuites().size());
164-
assertEquals("Wrong number of test cases", 1, testResult.getTotalCount());
165-
assertEquals("Wrong duration for test result", 1.0, testResult.getDuration(), 0.01);
166-
}
167153

168154
@Issue("JENKINS-41134")
169155
@Test
@@ -246,6 +232,36 @@ public void testSuiteWithMultipleClasses() throws IOException, URISyntaxExceptio
246232
assertEquals("Wrong duration for test class", 93.0, class2.getDuration(), 0.1);
247233
}
248234

235+
@Issue("JENKINS-48583")
236+
@Test
237+
public void testMergeOriginalAntOutput() throws IOException, URISyntaxException {
238+
TestResult testResult = new TestResult();
239+
testResult.parse(getDataFile("JENKINS-48583/TEST-com.sample.test.TestMessage.xml"), null);
240+
testResult.parse(getDataFile("JENKINS-48583/TEST-com.sample.test.TestMessage2.xml"), null);
241+
testResult.parse(getDataFile("JENKINS-48583/TESTS-TestSuites.xml"), null);
242+
testResult.parse(getDataFile("JENKINS-48583/TEST-com.sample.test.TestMessage.xml"), null);
243+
testResult.tally();
244+
245+
assertEquals("Wrong number of testsuites", 2, testResult.getSuites().size());
246+
assertEquals("Wrong number of test cases", 7, testResult.getTotalCount());
247+
}
248+
249+
/**
250+
* Sometimes legitimage test cases are split over multiple files with identical timestamps.
251+
*/
252+
@Issue("JENKINS-48583")
253+
@Test
254+
public void testNonDuplicatedTestSuiteIsCounted() throws IOException, URISyntaxException {
255+
TestResult testResult = new TestResult();
256+
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b.xml"), null);
257+
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b_duplicate.xml"), null);
258+
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b_nonduplicate.xml"), null);
259+
testResult.tally();
260+
261+
assertEquals("Wrong number of testsuites", 1, testResult.getSuites().size());
262+
assertEquals("Wrong number of test cases", 3, testResult.getTotalCount());
263+
}
264+
249265
@Issue("JENKINS-63113")
250266
@Test
251267
public void testTestcaseWithEmptyName() throws Exception {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="TestSuite_b" tests="1" errors="0" failures="0" skip="0" timestamp="2012-01-01T00:00:00">
3+
<testcase classname="TestFoo" name="bar2" time="1" />
4+
</testsuite>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<testsuite errors="0" failures="0" hostname="myhost" name="com.sample.test.TestMessage" skipped="0" tests="1" time="0.063" timestamp="2015-01-13T07:23:07">
3+
<properties>
4+
</properties>
5+
<testcase classname="com.sample.test.TestMessage" name="test_welcome_message" time="0.002" />
6+
<system-out><![CDATA[]]></system-out>
7+
<system-err><![CDATA[]]></system-err>
8+
</testsuite>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<testsuite errors="0" failures="0" hostname="myhost" name="com.sample.test.TestMessage2" skipped="0" tests="2" time="0.06" timestamp="2015-01-13T07:23:08">
3+
<properties>
4+
</properties>
5+
<testcase classname="com.sample.test.TestMessage2" name="test_welcome_message_2" time="0.001" />
6+
<testcase classname="com.sample.test.TestMessage2" name="test_welcome_message_3" time="0.003" />
7+
<system-out><![CDATA[]]></system-out>
8+
<system-err><![CDATA[]]></system-err>
9+
</testsuite>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<testsuites>
3+
<testsuite errors="0" failures="0" hostname="myhost" id="0" name="TestMessage" package="com.sample.test" skipped="0" tests="1" time="0.063" timestamp="2015-01-13T07:23:07">
4+
<properties>
5+
</properties>
6+
<testcase classname="com.sample.test.TestMessage" name="test_welcome_message" time="0.002" />
7+
<system-out><![CDATA[]]></system-out>
8+
<system-err><![CDATA[]]></system-err>
9+
</testsuite>
10+
<testsuite errors="0" failures="0" hostname="myhost" id="1" name="TestMessage2" package="com.sample.test" skipped="0" tests="2" time="0.06" timestamp="2015-01-13T07:23:08">
11+
<properties>
12+
</properties>
13+
<testcase classname="com.sample.test.TestMessage2" name="test_welcome_message_2" time="0.001" />
14+
<testcase classname="com.sample.test.TestMessage2" name="test_welcome_message_3" time="0.003" />
15+
<system-out><![CDATA[]]></system-out>
16+
<system-err><![CDATA[]]></system-err>
17+
</testsuite>
18+
</testsuites>

0 commit comments

Comments
 (0)