@Test public void testResumeBlocked() throws Exception { final String jobName = "survivesEverything"; final String[] logStart = new String[1]; final List<FlowNode> nodesOut = new ArrayList<FlowNode>(); story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY); run.getParent().setResumeBlocked(true); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); } logStart[0] = JenkinsRule.getLog(run); nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution())); nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR); } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild(); verifyFailedCleanly(story.j.jenkins, run); assertIncludesNodes(nodesOut, run); } }); }
/** Verify that if the master dies messily and we're not durable against that, build fails cleanly. */ @Test public void testDurableAgainstCleanRestartFailsWithDirtyShutdown() throws Exception { final String[] logStart = new String[1]; story.addStepWithDirtyShutdown(new Statement() { @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); } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName("durableAgainstClean", WorkflowJob.class).getLastBuild(); verifyFailedCleanly(story.j.jenkins, run); story.j.assertLogContains(logStart[0], run); } }); }
/** * Sanity check that fully durable pipelines can survive hard kills. */ @Test public void testFullyDurableSurvivesDirtyRestart() throws Exception { final String jobName = "survivesEverything"; final String[] logStart = new String[1]; story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); } logStart[0] = JenkinsRule.getLog(run); } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild(); verifySafelyResumed(story.j, run, false, logStart[0]); } }); }
final List<FlowNode> nodesOut = new ArrayList<FlowNode>(); story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable {
final String[] logStart = new String[1]; story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable {
final String[] logStart = new String[1]; final List<FlowNode> nodesOut = new ArrayList<FlowNode>(); story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable {
/** Verify that if the master dies messily and FlowNode storage is lost entirely we fail the build cleanly. */ @Test @Issue("JENKINS-48824") public void testDurableAgainstCleanRestartFailsWithBogusStorageFile() throws Exception { final String[] logStart = new String[1]; story.addStepWithDirtyShutdown(new Statement() { @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); CpsFlowExecution exec = (CpsFlowExecution)(run.getExecution()); // Ensure the storage file is unreadable try (FileChannel fis = new FileOutputStream(new File(exec.getStorageDir(), "flowNodeStore.xml")).getChannel()) { fis.truncate(5); // Leave a tiny bit just to make things more interesting } } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName("durableAgainstClean", WorkflowJob.class).getLastBuild(); verifyFailedCleanly(story.j.jenkins, run); story.j.assertLogContains(logStart[0], run); } }); }
story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable {