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);
}
});
}
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()));
}
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);
}
}
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]);
}
});
}
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;
}
Aggregations