Skip to content

Commit

Permalink
[FIXED JENKINS-48250] Log errors from JUnit parsing to FlowNode log
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Nov 28, 2017
1 parent fdf6915 commit 2234f40
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Expand Up @@ -46,14 +46,19 @@ protected TestResultSummary run() throws Exception {
pipelineTestDetails.setNodeId(nodeId);
pipelineTestDetails.setEnclosingBlocks(getEnclosingBlockIds(enclosingBlocks));
pipelineTestDetails.setEnclosingBlockNames(getEnclosingBlockNames(enclosingBlocks));
TestResultAction testResultAction = JUnitResultArchiver.parseAndAttach(step, pipelineTestDetails, run, workspace, launcher, listener);
try {
TestResultAction testResultAction = JUnitResultArchiver.parseAndAttach(step, pipelineTestDetails, run, workspace, launcher, listener);

if (testResultAction != null) {
// TODO: Once JENKINS-43995 lands, update this to set the step status instead of the entire build.
if (testResultAction.getResult().getFailCount() > 0) {
run.setResult(Result.UNSTABLE);
if (testResultAction != null) {
// TODO: Once JENKINS-43995 lands, update this to set the step status instead of the entire build.
if (testResultAction.getResult().getFailCount() > 0) {
run.setResult(Result.UNSTABLE);
}
return new TestResultSummary(testResultAction.getResult().getResultByNode(nodeId));
}
return new TestResultSummary(testResultAction.getResult().getResultByNode(nodeId));
} catch (Exception e) {
listener.getLogger().println(e.getMessage());
throw e;
}

return new TestResultSummary();
Expand Down
Expand Up @@ -8,15 +8,19 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.junit.CaseResult;
import hudson.tasks.junit.Messages;
import hudson.tasks.junit.TestDataPublisher;
import hudson.tasks.junit.TestResult;
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.junit.TestResultTest;
import hudson.tasks.test.PipelineBlockWithTests;
import org.hamcrest.CoreMatchers;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
import org.jenkinsci.plugins.workflow.actions.LogAction;
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
Expand All @@ -34,6 +38,7 @@
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -43,6 +48,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

public class JUnitResultsStepTest {
Expand All @@ -66,6 +72,7 @@ public void configRoundTrip() throws Exception {
st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'");
}

@Issue("JENKINS-48250")
@Test
public void emptyFails() throws Exception {
WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "emptyFails");
Expand All @@ -78,7 +85,23 @@ public void emptyFails() throws Exception {

WorkflowRun r = j.scheduleBuild2(0).waitForStart();
rule.assertBuildStatus(Result.FAILURE, rule.waitForCompletion(r));
rule.assertLogContains("ERROR: No test report files were found. Configuration error?", r);
rule.assertLogContains("ERROR: " + Messages.JUnitResultArchiver_NoTestReportFound(), r);
FlowExecution execution = r.getExecution();
DepthFirstScanner scanner = new DepthFirstScanner();
FlowNode f = scanner.findFirstMatch(execution, new Predicate<FlowNode>() {
@Override
public boolean apply(@Nullable FlowNode input) {
return input instanceof StepAtomNode &&
((StepAtomNode) input).getDescriptor() instanceof JUnitResultsStep.DescriptorImpl;
}
});
assertNotNull(f);
LogAction logAction = f.getPersistentAction(LogAction.class);
assertNotNull(logAction);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
logAction.getLogText().writeRawLogTo(0, baos);
String log = baos.toString();
assertThat(log, CoreMatchers.containsString(Messages.JUnitResultArchiver_NoTestReportFound()));
}

@Test
Expand Down

0 comments on commit 2234f40

Please sign in to comment.