use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testPauseForcesLowDurabilityToPersist.
/**
* Verifies that paused pipelines survive dirty restarts
*/
@Test
public void testPauseForcesLowDurabilityToPersist() throws Exception {
final String jobName = "durableAgainstClean";
final String[] logStart = new String[1];
story.addStepWithDirtyShutdown(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);
if (run.getExecution() instanceof CpsFlowExecution) {
CpsFlowExecution cpsFlow = (CpsFlowExecution) (run.getExecution());
cpsFlow.pause(true);
long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS);
while (System.nanoTime() < timeout && !cpsFlow.isPaused()) {
Thread.sleep(100L);
}
}
}
});
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
if (run.getExecution() instanceof CpsFlowExecution) {
CpsFlowExecution cpsFlow = (CpsFlowExecution) (run.getExecution());
cpsFlow.pause(false);
long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS);
while (System.nanoTime() < timeout && cpsFlow.isPaused()) {
Thread.sleep(100L);
}
}
Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint());
assertBaseStorageType(run.getExecution(), BulkFlowNodeStorage.class);
verifySafelyResumed(story.j, run, false, logStart[0]);
}
});
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testResumeBlocked.
@Test
public void testResumeBlocked() 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(true);
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);
}
});
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);
}
});
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method verifySafelyResumed.
/**
* If it's a {@link SemaphoreStep} we test less rigorously because that blocks async GraphListeners.
*/
static void verifySafelyResumed(JenkinsRule rule, WorkflowRun run, boolean isSemaphore, String logStart) throws Exception {
assert run.isBuilding();
FlowExecution exec = run.getExecution();
// Assert that we have the appropriate flow graph entries
List<FlowNode> heads = exec.getCurrentHeads();
Assert.assertEquals(1, heads.size());
FlowNode node = heads.get(0);
String name = node.getDisplayFunctionName();
Assert.assertTrue("Head node not a semaphore step or sleep: " + name, "semaphore".equals(name) || "sleep".equals(name));
if (!isSemaphore) {
Assert.assertNotNull(node.getPersistentAction(TimingAction.class));
Assert.assertNotNull(node.getPersistentAction(ArgumentsAction.class));
Assert.assertNotNull(node.getAction(LogAction.class));
} else {
SemaphoreStep.success("halt/1", Result.SUCCESS);
}
assertHasTimingAction(run.getExecution());
rule.waitForCompletion(run);
verifySucceededCleanly(rule.jenkins, run);
rule.assertLogContains(logStart, run);
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method verifyCompletedCleanly.
/**
* Verifies all the universal post-build cleanup was done, regardless of pass/fail state.
*/
static void verifyCompletedCleanly(Jenkins j, WorkflowRun run) throws Exception {
// Assert that we have the appropriate flow graph entries
FlowExecution exec = run.getExecution();
List<FlowNode> heads = exec.getCurrentHeads();
Assert.assertEquals(1, heads.size());
verifyNoTasksRunning(j);
Assert.assertEquals(0, exec.getCurrentExecutions(false).get().size());
if (exec instanceof CpsFlowExecution) {
CpsFlowExecution cpsFlow = (CpsFlowExecution) exec;
assert cpsFlow.getStorage() != null;
Assert.assertFalse("Should always be able to retrieve script", StringUtils.isEmpty(cpsFlow.getScript()));
Assert.assertNull("We should have no Groovy shell left or that's a memory leak", cpsFlow.getShell());
Assert.assertNull("We should have no Groovy shell left or that's a memory leak", cpsFlow.getTrustedShell());
}
verifyExecutionRemoved(run);
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method verifyFailedCleanly.
static void verifyFailedCleanly(Jenkins j, WorkflowRun run) throws Exception {
if (run.isBuilding()) {
// Give the run a little bit of time to see if it can resume or not
FlowExecution exec = run.getExecution();
if (exec instanceof CpsFlowExecution) {
waitForBuildToResumeOrFail(run);
} else {
Thread.sleep(4000L);
}
}
if (run.getExecution() instanceof CpsFlowExecution) {
CpsFlowExecution cfe = (CpsFlowExecution) (run.getExecution());
assert cfe.isComplete() || (cfe.programPromise != null && cfe.programPromise.isDone());
}
assert !run.isBuilding();
if (run.getExecution() instanceof CpsFlowExecution) {
Assert.assertEquals(Result.FAILURE, ((CpsFlowExecution) run.getExecution()).getResult());
}
Assert.assertEquals(Result.FAILURE, run.getResult());
assert !run.isBuilding();
// TODO verify all blocks cleanly closed out, so Block start and end nodes have same counts and FlowEndNode is last node
verifyCompletedCleanly(j, run);
}
Aggregations