/* for tests */ CpsThreadDump threadDumpSynchronous() throws InterruptedException, ExecutionException { execution.waitForSuspension(); return execution.getThreadDump(); }
public String getThreadDump() { return execution.getThreadDump().toString(); }
@Override public void writeTo(OutputStream outputStream) throws IOException { PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputStream, Charsets.UTF_8)); for (FlowExecution flow : FlowExecutionList.get()) { if (flow instanceof CpsFlowExecution) { pw.println("Build: " + flow.getOwner().getExecutable()); ((CpsFlowExecution) flow).getThreadDump().print(pw); pw.println("Approximate graph size: " + ((CpsFlowExecution) flow).approximateNodeCount()); pw.println(); } } pw.flush(); } });
@Test public void getStatus() throws Exception { WorkflowJob p = r.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("slowBlock {semaphore 'wait'}", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); startEnter.acquire(); assertThat(((CpsFlowExecution) b.getExecution()).getThreadDump().toString(), containsString("at DSL.slowBlock(running in thread: org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution [#")); Thread.sleep(250); // give CPS thread some time to go back to sleep assertTrue(SynchronousNonBlockingStepExecutionTest.blocksRestart(b)); startExit.release(); SemaphoreStep.waitForStart("wait/1", b); assertThat(((CpsFlowExecution) b.getExecution()).getThreadDump().toString(), containsString("at DSL.slowBlock(not currently scheduled, or running blocks)")); while (SynchronousNonBlockingStepExecutionTest.blocksRestart(b)) { Thread.sleep(100); // as above } SemaphoreStep.success("wait/1", null); endEnter.acquire(); assertThat(((CpsFlowExecution) b.getExecution()).getThreadDump().toString(), containsString("at DSL.slowBlock(running in thread: org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution [#")); Thread.sleep(250); // as above assertTrue(SynchronousNonBlockingStepExecutionTest.blocksRestart(b)); endExit.release(); r.assertBuildStatusSuccess(r.waitForCompletion(b)); }
@Test public void nativeMethods() throws Exception { p.setDefinition(new CpsFlowDefinition( "@NonCPS def untransformed() {Thread.sleep(Long.MAX_VALUE)}\n" + "def helper() {echo 'sleeping'; /* flush output */ sleep 1; untransformed()}\n" + "helper()", false)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get(); j.waitForMessage("sleeping", b); do { // wait for the CPS VM to be busy (opposite of waitForSuspension) Thread.sleep(100); } while (!e.blocksRestart()); CpsThreadDump td = e.getThreadDump(); td.print(System.out); assertStackTrace(td.getThreads().get(0), // TODO would like to see untransformed and Thread.sleep here "WorkflowScript.helper(WorkflowScript:2)", "WorkflowScript.run(WorkflowScript:3)"); b.doKill(); }