Search in sources :

Example 1 with StepNode

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);
    }
}
Also used : ErrorAction(org.jenkinsci.plugins.workflow.actions.ErrorAction) StepNode(org.jenkinsci.plugins.workflow.cps.nodes.StepNode) FlowGraphWalker(org.jenkinsci.plugins.workflow.graph.FlowGraphWalker) ArrayList(java.util.ArrayList) List(java.util.List) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ErrorAction (org.jenkinsci.plugins.workflow.actions.ErrorAction)1 StepEndNode (org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode)1 StepNode (org.jenkinsci.plugins.workflow.cps.nodes.StepNode)1 FlowGraphWalker (org.jenkinsci.plugins.workflow.graph.FlowGraphWalker)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 Test (org.junit.Test)1