@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(); }
/** Verifies all the assumptions about a cleanly finished build. */ static void assertCompletedCleanly(WorkflowRun run) throws Exception { while (run.isBuilding()) { Thread.sleep(100); // TODO seems to be unpredictable } Assert.assertNotNull(run.getResult()); FlowExecution fe = run.getExecution(); FlowExecutionList.get().forEach(f -> { if (fe != null && f == fe) { Assert.fail("FlowExecution still in FlowExecutionList!"); } }); Assert.assertTrue("Queue not empty after completion!", Queue.getInstance().isEmpty()); if (fe instanceof CpsFlowExecution) { CpsFlowExecution cpsExec = (CpsFlowExecution)fe; Assert.assertTrue(cpsExec.isComplete()); Assert.assertEquals(Boolean.TRUE, cpsExec.done); Assert.assertEquals(1, cpsExec.getCurrentHeads().size()); Assert.assertTrue(cpsExec.isComplete()); Assert.assertTrue(cpsExec.getCurrentHeads().get(0) instanceof FlowEndNode); Assert.assertTrue(cpsExec.startNodes == null || cpsExec.startNodes.isEmpty()); while (cpsExec.blocksRestart()) { Thread.sleep(100); // TODO ditto } } else { System.out.println("WARNING: no FlowExecutionForBuild"); } }