use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testDeserialize.
/**
* Helper function to test direct file deserialization for an execution
*/
private void testDeserialize(FlowExecution execution) throws Exception {
if (!(execution instanceof CpsFlowExecution) || !(((CpsFlowExecution) execution).getStorage() instanceof SimpleXStreamFlowNodeStorage)) {
// Test is unfortunately coupled to the implementation -- otherwise it will simply hit caches
return;
}
SimpleXStreamFlowNodeStorage storage = (SimpleXStreamFlowNodeStorage) (((CpsFlowExecution) execution).getStorage());
Method getFileM = SimpleXStreamFlowNodeStorage.class.getDeclaredMethod("getNodeFile", String.class);
getFileM.setAccessible(true);
List<FlowNode> nodes = new DepthFirstScanner().allNodes(execution.getCurrentHeads());
Collections.sort(nodes, FlowScanningUtils.ID_ORDER_COMPARATOR);
Field nodeExecutionF = FlowNode.class.getDeclaredField("exec");
nodeExecutionF.setAccessible(true);
// Read each node via deserialization from storage, and sanity check the node, the actions, and the ArgumentsAction read back right
for (FlowNode f : nodes) {
XmlFile file = (XmlFile) (getFileM.invoke(storage, f.getId()));
Object tagObj = file.read();
Assert.assertNotNull(tagObj);
// Check actions & node in the Tag object, but without getting at the private Tag class
Field actionField = tagObj.getClass().getDeclaredField("actions");
Field nodeField = tagObj.getClass().getDeclaredField("node");
actionField.setAccessible(true);
nodeField.setAccessible(true);
Action[] deserializedActions = (Action[]) actionField.get(tagObj);
FlowNode deserializedNode = (FlowNode) (nodeField.get(tagObj));
nodeExecutionF.set(deserializedNode, f.getExecution());
Assert.assertNotNull(deserializedNode);
if (f.getActions().size() > 0) {
Assert.assertNotNull(deserializedActions);
Assert.assertEquals(f.getActions().size(), deserializedActions.length);
}
ArgumentsAction expectedInfoAction = f.getPersistentAction(ArgumentsAction.class);
if (expectedInfoAction != null) {
Action deserializedInfoAction = Iterables.getFirst(Iterables.filter(Lists.newArrayList(deserializedActions), Predicates.instanceOf(ArgumentsAction.class)), null);
Assert.assertNotNull(deserializedInfoAction);
ArgumentsAction ArgumentsAction = (ArgumentsAction) deserializedInfoAction;
// Compare original and deserialized step arguments to see if they match
Assert.assertEquals(ArgumentsAction.getStepArgumentsAsString(f), ArgumentsAction.getStepArgumentsAsString(deserializedNode));
Map<String, Object> expectedParams = expectedInfoAction.getArguments();
Map<String, Object> deserializedParams = ArgumentsAction.getArguments();
Assert.assertEquals(expectedParams.size(), deserializedParams.size());
for (String s : expectedParams.keySet()) {
Object expectedVal = expectedParams.get(s);
Object actualVal = deserializedParams.get(s);
if (expectedVal instanceof Comparable) {
Assert.assertEquals(actualVal, expectedVal);
}
}
}
}
}
use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsoleNotStoredArgument.
@Ignore("TODO ArgumentsAction.getResolvedArguments does not yet handle NotStoredReason sensibly")
@Test
public void metastepConsoleNotStoredArgument() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
// cf. ArgumentsAction.MAX_RETAINED_LENGTH
String spaces = StringUtils.repeat(" ", 1025);
p.setDefinition(new CpsFlowDefinition("node {\n" + " configFileProvider([]) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " junit 'x.xml," + spaces + "'\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);
}
use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsoleRaw.
@Test
public void metastepConsoleRaw() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n" + " wrap(new org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper([])) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " step(new hudson.tasks.junit.JUnitResultArchiver('x.xml'))\n" + " }\n" + "}", false));
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);
}
use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsole.
@Issue("JENKINS-45109")
@Test
public void metastepConsole() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n" + " configFileProvider([]) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " junit '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);
}
use of org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner 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);
}
});
}
Aggregations