use of org.jenkinsci.plugins.workflow.cps.nodes.StepNode in project workflow-cps-plugin by jenkinsci.
the class CpsBodyExecutionTest method synchronousExceptionInBody.
/**
* When the body of a step is synchronous and explodes, the failure should be recorded and the pipeline job
* should move on.
*
* But instead, this hangs because CpsBodyExecution has a bug in how it handles this case.
* It tries to launch the body (in this case the 'bodyBlock' method) in a separate CPS thread,
* and puts the parent CPS thread on hold. Yet when the child CPS thread ends with an exception,
* it fails to record this result correctly, and it gets into the eternal sleep in which
* the parent CPS thread expects to be notified of the outcome of the child CPS thread, which
* never arrives.
*/
@Test
public void synchronousExceptionInBody() throws Exception {
WorkflowJob p = jenkins.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition("synchronousExceptionInBody()", true));
WorkflowRun b = jenkins.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
jenkins.assertLogContains(EmperorHasNoClothes.class.getName(), b);
{
// assert the shape of FlowNodes
FlowGraphWalker w = new FlowGraphWalker(b.getExecution());
List<String> nodes = new ArrayList<>();
for (FlowNode n : w) {
String s = n.getClass().getSimpleName();
if (n instanceof StepNode) {
StepNode sn = (StepNode) n;
s += ":" + sn.getDescriptor().getFunctionName();
}
if (n instanceof StepEndNode) {
// this should have recorded a failure
ErrorAction e = n.getAction(ErrorAction.class);
assertEquals(EmperorHasNoClothes.class, e.getError().getClass());
}
nodes.add(s);
}
assertEquals(Arrays.asList("FlowEndNode", // this for the end of invoking a body
"StepEndNode:synchronousExceptionInBody", // this for invoking a body
"StepStartNode:synchronousExceptionInBody", // letting steps take over the FlowNode creation that should solve this.
"StepAtomNode:synchronousExceptionInBody", "FlowStartNode"), nodes);
}
}
Aggregations