use of org.jenkinsci.plugins.workflow.flow.FlowExecutionListener in project workflow-job-plugin by jenkinsci.
the class WorkflowRunRestartTest method flowExecutionListener.
@Issue("JENKINS-43055")
@Test
public void flowExecutionListener() {
story.then(r -> {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'Running for listener'\n" + "sleep 0\n" + "semaphore 'wait'\n" + "sleep 0\n" + "semaphore 'post-resume'\n" + "sleep 0\n" + "error 'fail'\n", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
ExecListener listener = ExtensionList.lookup(FlowExecutionListener.class).get(ExecListener.class);
assertNotNull(listener);
assertTrue(listener.graphListener.wasCalledWithFlowStartNode);
assertEquals(1, listener.created);
assertEquals(1, listener.started);
assertEquals(0, listener.resumed);
assertEquals(0, listener.finished);
});
story.then(r -> {
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getLastBuild();
assertTrue(b.isBuilding());
SemaphoreStep.success("wait/1", null);
SemaphoreStep.waitForStart("post-resume/1", b);
ExecListener listener = ExtensionList.lookup(FlowExecutionListener.class).get(ExecListener.class);
assertNotNull(listener);
assertEquals(0, listener.created);
assertEquals(0, listener.started);
assertEquals(1, listener.resumed);
assertEquals(0, listener.finished);
SemaphoreStep.success("post-resume/1", null);
r.assertBuildStatus(Result.FAILURE, r.waitForCompletion(b));
r.assertLogContains("Running for listener", b);
assertEquals(0, listener.created);
assertEquals(0, listener.started);
assertEquals(1, listener.resumed);
assertEquals(1, listener.finished);
assertTrue(listener.graphListener.wasCalledBeforeExecListener);
});
}
Aggregations