use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testPipelineFinishesFlowGraph.
/**
* Verify that if we bomb out because we cannot resume, we at least try to finish the flow graph if we have something to work with.
*/
@Test
// Can be fleshed out later if we have a valid need for it.
@Ignore
public void testPipelineFinishesFlowGraph() throws Exception {
final String[] logStart = new String[1];
final List<FlowNode> nodesOut = new ArrayList<FlowNode>();
story.addStepWithDirtyShutdown(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, "durableAgainstClean", FlowDurabilityHint.PERFORMANCE_OPTIMIZED);
Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint());
logStart[0] = JenkinsRule.getLog(run);
if (run.getExecution() instanceof CpsFlowExecution) {
// Pause and unPause to force persistence
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);
}
nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR);
cpsFlow.pause(false);
timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS);
while (System.nanoTime() < timeout && cpsFlow.isPaused()) {
Thread.sleep(100L);
}
// Ensures we're marked as can-not-resume
cpsFlow.persistedClean = false;
cpsFlow.saveOwner();
}
}
});
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowRun run = story.j.jenkins.getItemByFullName("durableAgainstClean", WorkflowJob.class).getLastBuild();
verifyFailedCleanly(story.j.jenkins, run);
story.j.assertLogContains(logStart[0], run);
assertIncludesNodes(nodesOut, run);
}
});
}
use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsoleShellClass.
@Test
public void metastepConsoleShellClass() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n" + " wrap([$class: 'ConfigFileBuildWrapper', managedFiles: []]) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " step([$class: 'JUnitResultArchiver', testResults: 'x.xml'])\n" + " }\n" + "}", true));
WorkflowRun b = r.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0));
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step"));
assertThat(coreStepNodes, hasSize(1));
assertEquals("junit", coreStepNodes.get(0).getDisplayFunctionName());
assertEquals(r.jenkins.getDescriptor(JUnitResultArchiver.class).getDisplayName(), coreStepNodes.get(0).getDisplayName());
List<FlowNode> coreWrapperStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), Predicates.and(new NodeStepTypePredicate("wrap"), new Predicate<FlowNode>() {
@Override
public boolean apply(FlowNode n) {
return n instanceof StepStartNode && !((StepStartNode) n).isBody();
}
}));
assertThat(coreWrapperStepNodes, hasSize(1));
assertEquals("configFileProvider", coreWrapperStepNodes.get(0).getDisplayFunctionName());
assertEquals(r.jenkins.getDescriptor(ConfigFileBuildWrapper.class).getDisplayName() + " : Start", coreWrapperStepNodes.get(0).getDisplayName());
r.assertLogContains("[Pipeline] junit", b);
r.assertLogContains("[Pipeline] configFileProvider", b);
r.assertLogContains("[Pipeline] // configFileProvider", b);
}
Aggregations