提交 17fdfab3 编写于 作者: S Stephen Connolly

[FIXED JENKINS-240006] Customize number of Junit test failures that affect weather

- Implemented as an amplification factor.
上级 5b7d59a7
......@@ -52,6 +52,7 @@ import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
......@@ -82,6 +83,8 @@ public class JUnitResultArchiver extends Recorder {
*/
private final DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers;
private final Double healthScaleFactor;
/**
* left for backwards compatibility
* @deprecated since 2009-08-09.
......@@ -97,14 +100,24 @@ public class JUnitResultArchiver extends Recorder {
this(testResults, false, testDataPublishers);
}
@DataBoundConstructor
@Deprecated
public JUnitResultArchiver(
String testResults,
boolean keepLongStdio,
DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers) {
this(testResults, keepLongStdio, testDataPublishers, 1.0);
}
@DataBoundConstructor
public JUnitResultArchiver(
String testResults,
boolean keepLongStdio,
DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers,
double healthScaleFactor) {
this.testResults = testResults;
this.keepLongStdio = keepLongStdio;
this.testDataPublishers = testDataPublishers;
this.healthScaleFactor = Math.max(0.0,healthScaleFactor);
}
/**
......@@ -133,6 +146,7 @@ public class JUnitResultArchiver extends Recorder {
} catch (NullPointerException npe) {
throw new AbortException(Messages.JUnitResultArchiver_BadXML(testResults));
}
action.setHealthScaleFactor(getHealthScaleFactor()); // TODO do we want to move this to the constructor?
result.freeze(action);
if (result.isEmpty()) {
// most likely a configuration error in the job - e.g. false pattern to match the JUnit result files
......@@ -192,7 +206,11 @@ public class JUnitResultArchiver extends Recorder {
return testResults;
}
public DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> getTestDataPublishers() {
public double getHealthScaleFactor() {
return healthScaleFactor == null ? 1.0 : healthScaleFactor;
}
public DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> getTestDataPublishers() {
return testDataPublishers;
}
......@@ -248,5 +266,15 @@ public class JUnitResultArchiver extends Recorder {
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}
public FormValidation doCheckHealthScaleFactor(@QueryParameter double value) {
if (value < 1e-7) return FormValidation.warning("Test health reporting disabled");
return FormValidation.ok(Messages.JUnitResultArchiver_HealthScaleFactorAnalysis(
1,
(int) (100.0 - Math.max(0.0, Math.min(100.0, 1 * value))),
5,
(int) (100.0 - Math.max(0.0, Math.min(100.0, 5 * value)))
));
}
}
}
......@@ -26,6 +26,7 @@ package hudson.tasks.junit;
import com.thoughtworks.xstream.XStream;
import hudson.XmlFile;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.tasks.test.AbstractTestResultAction;
......@@ -60,6 +61,7 @@ public class TestResultAction extends AbstractTestResultAction<TestResultAction>
private int failCount;
private int skipCount;
private Integer totalCount;
private Double healthScaleFactor;
private List<Data> testData = new ArrayList<Data>();
@Deprecated
......@@ -139,7 +141,16 @@ public class TestResultAction extends AbstractTestResultAction<TestResultAction>
return totalCount;
}
@Override
@Override
public double getHealthScaleFactor() {
return healthScaleFactor == null ? 1.0 : healthScaleFactor;
}
public void setHealthScaleFactor(double healthScaleFactor) {
this.healthScaleFactor = Math.max(0.0,healthScaleFactor);
}
@Override
public List<CaseResult> getFailedTests() {
return getResult().getFailedTests();
}
......
......@@ -133,9 +133,15 @@ public abstract class AbstractTestResultAction<T extends AbstractTestResultActio
}
public HealthReport getBuildHealth() {
final double scaleFactor = getHealthScaleFactor();
if (scaleFactor < 1e-7) {
return null;
}
final int totalCount = getTotalCount();
final int failCount = getFailCount();
int score = (totalCount == 0) ? 100 : (int) (100.0 * (1.0 - ((double)failCount) / totalCount));
int score = (totalCount == 0)
? 100
: (int) (100.0 * Math.max(1.0, Math.min(0.0, 1.0 - (scaleFactor * failCount) / totalCount)));
Localizable description, displayName = Messages._AbstractTestResultAction_getDisplayName();
if (totalCount == 0) {
description = Messages._AbstractTestResultAction_zeroTestDescription(displayName);
......@@ -145,6 +151,19 @@ public abstract class AbstractTestResultAction<T extends AbstractTestResultActio
return new HealthReport(score, description);
}
/**
* Returns how much to scale the test related health by.
* @return a factor of {@code 1.0} to have the test health be the percentage of tests passing so 20% of tests
* failing will report as 80% health. A factor of {@code 2.0} will mean that 20% of tests failing will report as 60%
* health. A factor of {@code 2.5} will mean that 20% of test failing will report as 50% health. A factor of
* {@code 4.0} will mean that 20% of tests failing will report as 20% health. A factor of {@code 5.0} will mean
* that 20% (or more) of tests failing will report as 0% health. A factor of {@code 0.0} will disable test health
* reporting.
*/
public double getHealthScaleFactor() {
return 1.0;
}
/**
* Exposes this object to the remote API.
*/
......
......@@ -33,6 +33,9 @@ THE SOFTWARE.
<f:entry field="keepLongStdio" title="">
<f:checkbox name="keepLongStdio" checked="${instance.keepLongStdio}" title="${%Retain long standard output/error}"/>
</f:entry>
<f:entry field="healthScaleFactor" title="${%Health report amplification factor}">
<f:number default="1.0" min="0" step="0.1" size="10"/>
</f:entry>
<j:invokeStatic var="testDataPublisherDescriptors"
className="hudson.tasks.junit.TestDataPublisher" method="all" />
<j:if test="${testDataPublisherDescriptors.size() > 0}">
......
<div>
The amplification factor to apply to test failures when computing the test result contribution to the build health
score.
<br />
The default factor is <code>1.0</code>
<ul>
<li>A factor of <code>0.0</code> will disable the test result contribution to build health score.</li>
<li>A factor of <code>0.1</code> means that 10% of tests failing will score 99% health</li>
<li>A factor of <code>0.5</code> means that 10% of tests failing will score 95% health</li>
<li>A factor of <code>1.0</code> means that 10% of tests failing will score 10% health</li>
<li>A factor of <code>2.0</code> means that 10% of tests failing will score 20% health</li>
<li>A factor of <code>2.5</code> means that 10% of tests failing will score 25% health</li>
<li>A factor of <code>5.0</code> means that 10% of tests failing will score 50% health</li>
<li>A factor of <code>10.0</code> means that 10% of tests failing will score 0% health</li>
</ul>
The factor is persisted with the build results, so changes will only be reflected in new builds.
</div>
\ No newline at end of file
......@@ -36,6 +36,7 @@ JUnitResultArchiver.NoTestReportFound=No test report files were found. Configura
JUnitResultArchiver.Recording=Recording test results
JUnitResultArchiver.ResultIsEmpty=None of the test reports contained any result
JUnitResultArchiver.BadXML=Incorrect XML attributes for test results found in {0}
JUnitResultArchiver.HealthScaleFactorAnalysis={0}% failing tests scores as {1}% health. {2}% failing tests scores as {3}% health
CaseResult.Status.Passed=Passed
CaseResult.Status.Failed=Failed
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册