@RequirePOST public void doToggle() throws IOException { execution.pause(!execution.isPaused()); }
/** Waits until the build to resume or die. */ static void waitForBuildToResumeOrFail(WorkflowRun run) throws Exception { CpsFlowExecution execution = (CpsFlowExecution)(run.getExecution()); long nanoStartTime = System.nanoTime(); while (true) { if (!run.isBuilding()) { return; } long currentTime = System.nanoTime(); if (TimeUnit.SECONDS.convert(currentTime-nanoStartTime, TimeUnit.NANOSECONDS) > 10) { StringBuilder builder = new StringBuilder(); builder.append("Run result: "+run.getResult()); builder.append(" and execution != null:"+run.getExecution() != null+" "); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { CpsFlowExecution cpsFlow = (CpsFlowExecution)exec; builder.append(", FlowExecution is paused: "+cpsFlow.isPaused()) .append(", FlowExecution is complete: "+cpsFlow.isComplete()) .append(", FlowExecution result: "+cpsFlow.getResult()) .append(", FlowExecution PersistedClean: "+cpsFlow.persistedClean).append('\n'); } throw new TimeoutException("Build didn't resume or fail in a timely fashion. "+builder.toString()); } Thread.sleep(100L); } }
@Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.PERFORMANCE_OPTIMIZED); FlowExecution exec = run.getExecution(); assertBaseStorageType(exec, BulkFlowNodeStorage.class); logStart[0] = JenkinsRule.getLog(run); if (run.getExecution() instanceof CpsFlowExecution) { CpsFlowExecution cpsFlow = (CpsFlowExecution)(run.getExecution()); cpsFlow.pause(true); long timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && !cpsFlow.isPaused()) { Thread.sleep(100L); } } } });
@Override public void evaluate() throws Throwable { WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, "durableAgainstClean", FlowDurabilityHint.PERFORMANCE_OPTIMIZED); Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint()); logStart[0] = JenkinsRule.getLog(run); if (run.getExecution() instanceof CpsFlowExecution) { // Pause and unPause to force persistence CpsFlowExecution cpsFlow = (CpsFlowExecution)(run.getExecution()); cpsFlow.pause(true); long timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && !cpsFlow.isPaused()) { Thread.sleep(100L); } nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution())); nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR); cpsFlow.pause(false); timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && cpsFlow.isPaused()) { Thread.sleep(100L); } // Ensures we're marked as can-not-resume cpsFlow.persistedClean = false; cpsFlow.saveOwner(); } } });
@Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild(); if (run.getExecution() instanceof CpsFlowExecution) { CpsFlowExecution cpsFlow = (CpsFlowExecution)(run.getExecution()); cpsFlow.pause(false); long timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && cpsFlow.isPaused()) { Thread.sleep(100L); } } Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint()); assertBaseStorageType(run.getExecution(), BulkFlowNodeStorage.class); verifySafelyResumed(story.j, run, false, logStart[0]); } });
@Override public void evaluate() throws Throwable { WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class); WorkflowRun b = p.getLastBuild(); assertTrue(b.isBuilding()); CpsFlowExecution e = (CpsFlowExecution) b.getExecution(); assertTrue(e.isPaused()); JenkinsRule.WebClient wc = story.j.createWebClient(); WebRequest wrs = new WebRequest(wc.createCrumbedUrl(b.getUrl() + PauseUnpauseAction.URL + "/toggle"), HttpMethod.POST); wc.login("dev").getPage(wrs); assertFalse(e.isPaused()); story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)); assertFalse(e.isPaused()); } });
SemaphoreStep.waitForStart("one/1", b); final CpsFlowExecution e = (CpsFlowExecution) b.getExecution(); assertFalse(e.isPaused()); JenkinsRule.WebClient wc = story.j.createWebClient(); String toggleUrlRel = b.getUrl() + PauseUnpauseAction.URL + "/toggle"; assertTrue(e.isPaused()); story.j.waitForMessage("before", b); SemaphoreStep.success("one/1", null); assertTrue(e.isPaused());