Skip to content
Permalink
Browse files

JENKINS-37598: address review comments; put back time field, doesn't …

…throw exception
  • Loading branch information...
kgyrtkirk committed Mar 13, 2017
1 parent 8f3473b commit 319280f67394b2b0eda1fba589912f30bbd3ebcc
@@ -41,6 +41,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -59,6 +60,7 @@
*/
@ExportedBean
public final class SuiteResult implements Serializable {
private static final Logger LOGGER = Logger.getLogger(SuiteResult.class.getName());
private final String file;
private final String name;
private final String stdout;
@@ -72,8 +74,8 @@
/** Optional ID attribute of a test suite. E.g., Eclipse plug-ins tests always have the name 'tests' but a different id. **/
private String id;

/** Optional true if time attribute is present. E.g., Suites can use their own time attribute or the sum of their cases' times as before.**/
private boolean hasTimeAttr;
/** Optional time attribute of a test suite. E.g., Suites can use their own time attribute or the sum of their cases' times as before.**/
private String time;

/**
* All test cases.
@@ -165,9 +167,8 @@ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio) throws
this.timestamp = suite.attributeValue("timestamp");
this.id = suite.attributeValue("id");
// check for test suite time attribute
this.hasTimeAttr = suite.attributeValue("time")!=null;
if( hasTimeAttr ) {
duration = new TimeToFloat(suite.attributeValue("time")).parse();
if( ( this.time = suite.attributeValue("time") ) != null ){
duration = new TimeToFloat(this.time).parse();
}

Element ex = suite.element("error");
@@ -228,11 +229,18 @@ private SuiteResult(File xmlReport, Element suite, boolean keepLongStdio) throws
casesByName().put(cr.getName(), cr);

//if suite time was not specified use sum of the cases' times
if( !hasTimeAttr ){
if( !hasTimeAttr() ){
duration += cr.getDuration();
}
}

/**
* Returns true if the time attribute is present in this Suite.
*/
private boolean hasTimeAttr() {
return time != null;
}

@Exported(visibility=9)
public String getName() {
return name;
@@ -353,13 +361,13 @@ void setParent(hudson.tasks.junit.TestResult parent) {
/**
* Merges another SuiteResult into this one.
*
* @param sr
* @param sr the SuiteResult to merge into this one
*/
public void merge(SuiteResult sr) {
if (sr.hasTimeAttr ^ hasTimeAttr){
throw new IllegalStateException("Merging of suiteresults with incompatible time attribute usage is not supported.( "+getFile()+", "+sr.getFile()+")");
if (sr.hasTimeAttr() ^ hasTimeAttr()){
LOGGER.warning("Merging of suiteresults with incompatible time attribute may lead to incorrect durations in reports.( "+getFile()+", "+sr.getFile()+")");
}
if (hasTimeAttr) {
if (hasTimeAttr()) {
duration += sr.getDuration();
}
for (CaseResult cr : sr.getCases()) {
@@ -197,14 +197,6 @@ public void testMergeWithoutTime() throws Exception {
assertEquals(30, suite.getDuration(), 2);
}

@Issue("JENKINS-37598")
@Test(expected=Exception.class)
public void testMergeWithInconsistency() throws Exception {
TestResult testResult = new TestResult();
testResult.parse(getDataFile("junit-report-time-aggregation-invalid.xml"));
testResult.tally();
}

private static final XStream XSTREAM = new XStream2();

static {

This file was deleted.

Oops, something went wrong.

0 comments on commit 319280f

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