Search in sources :

Example 1 with ThreadInfo

use of org.jenkinsci.plugins.workflow.cps.CpsThreadDump.ThreadInfo in project workflow-cps-plugin by jenkinsci.

the class CpsThreadDumpTest method simple.

@Test
public void simple() throws Exception {
    p.setDefinition(new CpsFlowDefinition(StringUtils.join(asList("def foo() { bar() }", "def bar() {", "   semaphore 'x'", "}", "foo()"), "\n")));
    WorkflowRun b = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("x/1", b);
    CpsThreadDumpAction action = b.getAction(CpsThreadDumpAction.class);
    if (action == null) {
        FlowExecutionOwner owner = b.asFlowExecutionOwner();
        assertNotNull(owner);
        CpsFlowExecution exec = (CpsFlowExecution) owner.getOrNull();
        assertNotNull(exec);
        assertFalse(exec.isComplete());
        fail("not sure why CpsThreadDumpAction was missing here");
    }
    CpsThreadDump td = action.threadDumpSynchronous();
    td.print(System.out);
    {
        // verify that we got the right thread dump
        List<ThreadInfo> threads = td.getThreads();
        assertEquals(1, threads.size());
        ThreadInfo t = threads.get(0);
        assertEquals("Thread #0", t.getHeadline());
        assertStackTrace(t, "DSL.semaphore(waiting on x/1)", "WorkflowScript.bar(WorkflowScript:3)", "WorkflowScript.foo(WorkflowScript:1)", "WorkflowScript.run(WorkflowScript:5)");
    }
    SemaphoreStep.success("x/1", null);
    j.waitForCompletion(b);
    assertNull(b.getAction(CpsThreadDumpAction.class));
}
Also used : ThreadInfo(org.jenkinsci.plugins.workflow.cps.CpsThreadDump.ThreadInfo) FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 ThreadInfo (org.jenkinsci.plugins.workflow.cps.CpsThreadDump.ThreadInfo)1 FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 Test (org.junit.Test)1