Search in sources :

Example 6 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method testResumeBlockedAddedAfterRunStart.

@Test
@Issue("JENKINS-49961")
public void testResumeBlockedAddedAfterRunStart() throws Exception {
    final String jobName = "survivesEverything";
    final String[] logStart = new String[1];
    final List<FlowNode> nodesOut = new ArrayList<FlowNode>();
    story.addStepWithDirtyShutdown(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            Jenkins jenkins = story.j.jenkins;
            WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
            run.getParent().setResumeBlocked(false);
            FlowExecution exec = run.getExecution();
            if (exec instanceof CpsFlowExecution) {
                assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
            }
            logStart[0] = JenkinsRule.getLog(run);
            nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
            nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR);
            run.getParent().setResumeBlocked(true);
        }
    });
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
            verifyFailedCleanly(story.j.jenkins, run);
            assertIncludesNodes(nodesOut, run);
        }
    });
}
Also used : Statement(org.junit.runners.model.Statement) ArrayList(java.util.ArrayList) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) Jenkins(jenkins.model.Jenkins) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 7 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method verifyExecutionRemoved.

private static void verifyExecutionRemoved(WorkflowRun run) throws Exception {
    // Verify we've removed all FlowExcecutionList entries
    FlowExecutionList list = FlowExecutionList.get();
    for (FlowExecution fe : list) {
        if (fe == run.getExecution()) {
            Assert.fail("Run still has an execution in the list and should be removed!");
        }
    }
    Field f = list.getClass().getDeclaredField("runningTasks");
    f.setAccessible(true);
    CopyOnWriteList<FlowExecutionOwner> runningTasks = (CopyOnWriteList<FlowExecutionOwner>) (f.get(list));
    Assert.assertFalse(runningTasks.contains(run.asFlowExecutionOwner()));
}
Also used : FlowExecutionList(org.jenkinsci.plugins.workflow.flow.FlowExecutionList) Field(java.lang.reflect.Field) FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) CopyOnWriteList(hudson.util.CopyOnWriteList)

Example 8 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method waitForBuildToResumeOrFail.

/**
 * Waits until the build to resume or die.
 */
static void waitForBuildToResumeOrFail(WorkflowRun run) throws Exception {
    CpsFlowExecution execution = (CpsFlowExecution) (run.getExecution());
    long nanoStartTime = System.nanoTime();
    while (true) {
        if (!run.isBuilding()) {
            return;
        }
        long currentTime = System.nanoTime();
        if (TimeUnit.SECONDS.convert(currentTime - nanoStartTime, TimeUnit.NANOSECONDS) > 10) {
            StringBuilder builder = new StringBuilder();
            builder.append("Run result: " + run.getResult());
            builder.append(" and execution != null:" + run.getExecution() != null + " ");
            FlowExecution exec = run.getExecution();
            if (exec instanceof CpsFlowExecution) {
                CpsFlowExecution cpsFlow = (CpsFlowExecution) exec;
                builder.append(", FlowExecution is paused: " + cpsFlow.isPaused()).append(", FlowExecution is complete: " + cpsFlow.isComplete()).append(", FlowExecution result: " + cpsFlow.getResult()).append(", FlowExecution PersistedClean: " + cpsFlow.persistedClean).append('\n');
            }
            throw new TimeoutException("Build didn't resume or fail in a timely fashion. " + builder.toString());
        }
        Thread.sleep(100L);
    }
}
Also used : FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) TimeoutException(java.util.concurrent.TimeoutException)

Example 9 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method testDurableAgainstCleanRestartSurvivesIt.

/**
 * Verifies that if we're only durable against clean restarts, the pipeline will survive it.
 */
@Test
public void testDurableAgainstCleanRestartSurvivesIt() throws Exception {
    final String jobName = "durableAgainstClean";
    final String[] logStart = new String[1];
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            Jenkins jenkins = story.j.jenkins;
            WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.PERFORMANCE_OPTIMIZED);
            FlowExecution exec = run.getExecution();
            assertBaseStorageType(exec, BulkFlowNodeStorage.class);
            logStart[0] = JenkinsRule.getLog(run);
        }
    });
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
            Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint());
            assertBaseStorageType(run.getExecution(), BulkFlowNodeStorage.class);
            verifySafelyResumed(story.j, run, true, logStart[0]);
        }
    });
}
Also used : Jenkins(jenkins.model.Jenkins) Statement(org.junit.runners.model.Statement) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BulkFlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.BulkFlowNodeStorage) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 10 with FlowExecution

use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.

the class ReplayAction method getExecution.

@CheckForNull
private CpsFlowExecution getExecution() {
    FlowExecutionOwner owner = ((FlowExecutionOwner.Executable) run).asFlowExecutionOwner();
    if (owner == null) {
        return null;
    }
    FlowExecution exec = owner.getOrNull();
    return exec instanceof CpsFlowExecution ? (CpsFlowExecution) exec : null;
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) CheckForNull(javax.annotation.CheckForNull)

Aggregations

FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)28 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)10 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 Statement (org.junit.runners.model.Statement)7 Jenkins (jenkins.model.Jenkins)6 FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)6 AbortException (hudson.AbortException)5 IOException (java.io.IOException)5 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)4 DepthFirstScanner (org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner)4 FlowInterruptedException (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException)3 LineTransformationOutputStream (hudson.console.LineTransformationOutputStream)2 StreamBuildListener (hudson.model.StreamBuildListener)2 CopyOnWriteList (hudson.util.CopyOnWriteList)2 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 Date (java.util.Date)2