Skip to content
Permalink
Browse files

[Re-FIXED JENKINS-12457] 'Age' column on 'Test Result' tab may show i…

…ncorrect value when a test suite divided into multiple junit files
  • Loading branch information
kutzi committed Apr 6, 2012
1 parent a31a186 commit d9e87705e8d693bc9d028e1da8c614c0fb736cd3
@@ -58,8 +58,6 @@
<li class=bug>
Fixed: tests with the same name are no longer counted correctly.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-13214">issue 13214</a>)
Note that this reopens the bug:
<a href="https://issues.jenkins-ci.org/browse/JENKINS-12457">issue 12457</a>
<li class=rfe>
Added a tag to copy text into clipboard for plugins
<li class=rfe>
@@ -511,6 +511,10 @@ public Status getStatus() {
/*package*/ void setClass(ClassResult classResult) {
this.classResult = classResult;
}

void replaceParent(SuiteResult parent) {
this.parent = parent;
}

/**
* Constants that represent the status of this test.
@@ -186,20 +186,38 @@ public void parse(long buildTime, File baseDir, String[] reportFiles) throws IOE

private void add(SuiteResult sr) {
for (SuiteResult s : suites) {
// a common problem is that people parse TEST-*.xml as well as TESTS-TestSuite.xml
// see http://www.nabble.com/Problem-with-duplicate-build-execution-td17549182.html for discussion
if(s.getName().equals(sr.getName()) && eq(s.getTimestamp(),sr.getTimestamp())
&& eq(s.getId(),sr.getId()))
return; // duplicate
// JENKINS-12457: If a testsuite is distributed over multiple files, merge it into a single SuiteResult:
if(s.getName().equals(sr.getName()) && nullSafeEq(s.getId(),sr.getId())) {

// However, a common problem is that people parse TEST-*.xml as well as TESTS-TestSuite.xml.
// In that case consider the result file as a duplicate and discard it.
// see http://jenkins.361315.n4.nabble.com/Problem-with-duplicate-build-execution-td371616.html for discussion.
if(strictEq(s.getTimestamp(),sr.getTimestamp())) {
return;
}

for (CaseResult cr: sr.getCases()) {
s.addCase(cr);
cr.replaceParent(s);
}
return;
}
}
suites.add(sr);
duration += sr.getDuration();
}

private boolean eq(Object lhs, Object rhs) {
private boolean strictEq(Object lhs, Object rhs) {
return lhs != null && rhs != null && lhs.equals(rhs);
}

private boolean nullSafeEq(Object lhs, Object rhs) {
if (lhs == null) {
return rhs == null;
}
return lhs.equals(rhs);
}

/**
* Parses an additional report file.
*/
@@ -112,14 +112,34 @@ public void testDuplicateTestMethods() throws IOException, URISyntaxException {
testResult.parse(getDataFile("JENKINS-13214/29734.xml"));
testResult.tally();

// Ideally the suites should be merged as they are logically the same, but that doesn't work, yet
// See also JENKINS-12457
// Collection<SuiteResult> suites = testResult.getSuites();
// assertEquals("Wrong number of test suites", 1, suites.size());


assertEquals("Wrong number of test suites", 1, testResult.getSuites().size());
assertEquals("Wrong number of test cases", 3, testResult.getTotalCount());
}

@Bug(12457)
public void testTestSuiteDistributedOverMultipleFilesIsCountedAsOne() throws IOException, URISyntaxException {
TestResult testResult = new TestResult();
testResult.parse(getDataFile("JENKINS-12457/TestSuite_a1.xml"));
testResult.parse(getDataFile("JENKINS-12457/TestSuite_a2.xml"));
testResult.tally();

assertEquals("Wrong number of testsuites", 1, testResult.getSuites().size());
assertEquals("Wrong number of test cases", 2, testResult.getTotalCount());
}

/**
* A common problem is that people parse TEST-*.xml as well as TESTS-TestSuite.xml.
* See http://jenkins.361315.n4.nabble.com/Problem-with-duplicate-build-execution-td371616.html for discussion.
*/
public void testDuplicatedTestSuiteIsNotCounted() throws IOException, URISyntaxException {
TestResult testResult = new TestResult();
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b.xml"));
testResult.parse(getDataFile("JENKINS-12457/TestSuite_b_duplicate.xml"));
testResult.tally();

assertEquals("Wrong number of testsuites", 1, testResult.getSuites().size());
assertEquals("Wrong number of test cases", 1, testResult.getTotalCount());
}

private static final XStream XSTREAM = new XStream2();

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="TestSuite_a" tests="1" errors="0" failures="0" skip="0" timestamp="2012-04-05T10:50:00">
<testcase classname="TestFoo" name="bar" time="157.980" />
</testsuite>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="TestSuite_a" tests="1" errors="0" failures="0" skip="0" timestamp="2012-04-05T10:50:30">
<testcase classname="TestFoo" name="bar2" time="15.000" />
</testsuite>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="TestSuite_b" tests="1" errors="0" failures="0" skip="0" timestamp="2012-01-01T00:00:00">
<testcase classname="TestFoo" name="bar" time="1" />
</testsuite>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="TestSuite_b" tests="1" errors="0" failures="0" skip="0" timestamp="2012-01-01T00:00:00">
<testcase classname="TestFoo" name="bar" time="1" />
</testsuite>

0 comments on commit d9e8770

Please sign in to comment.
You can’t perform that action at this time.