use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testFullyDurableSurvivesDirtyRestart.
/**
* 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]);
}
});
}
use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testFullyDurableSurvivesCleanRestart.
/**
* Sanity check that fully durable pipelines shutdown and restart cleanly
*/
@Test
public void testFullyDurableSurvivesCleanRestart() throws Exception {
final String jobName = "survivesEverything";
final String[] logStart = new String[1];
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
Jenkins jenkins = story.j.jenkins;
WorkflowRun run = createAndRunBasicJob(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, true, logStart[0]);
}
});
}
use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testPauseForcesLowDurabilityToPersist.
/**
* Verifies that paused pipelines survive dirty restarts
*/
@Test
public void testPauseForcesLowDurabilityToPersist() throws Exception {
final String jobName = "durableAgainstClean";
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.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);
}
}
}
});
story.addStep(new Statement() {
@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]);
}
});
}
use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testResumeBlocked.
@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);
}
});
}
use of jenkins.model.Jenkins in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method fuzzTimingDurable.
/**
* Test interrupting build by randomly dying at unpredictable times.
*/
@Test
// Too long to run as part of main suite
@Ignore
@TimedRepeatRule.RepeatForTime(repeatMillis = 170_000)
public void fuzzTimingDurable() throws Exception {
final String jobName = "NestedParallelDurableJob";
final String[] logStart = new String[1];
final List<FlowNode> nodesOut = new ArrayList<FlowNode>();
// Create thread that eventually interrupts Jenkins with a hard shutdown at a random time interval
story.addStepWithDirtyShutdown(new Statement() {
@Override
public void evaluate() throws Throwable {
Jenkins jenkins = story.j.jenkins;
WorkflowJob job = jenkins.getItemByFullName(jobName, WorkflowJob.class);
if (job == null) {
// Job may already have been created
job = jenkins.createProject(WorkflowJob.class, jobName);
FlowDurabilityHint hint = FlowDurabilityHint.MAX_SURVIVABILITY;
TestDurabilityHintProvider provider = Jenkins.getInstance().getExtensionList(TestDurabilityHintProvider.class).get(0);
provider.registerHint(job.getFullName(), hint);
job.setDefinition(new CpsFlowDefinition("echo 'first'\n" + "def steps = [:]\n" + "steps['1'] = {\n" + " echo 'do 1 stuff'\n" + "}\n" + "steps['2'] = {\n" + " echo '2a'\n" + " echo '2b'\n" + " def nested = [:]\n" + " nested['2-1'] = {\n" + " echo 'do 2-1'\n" + " } \n" + " nested['2-2'] = {\n" + " sleep 1\n" + " echo '2 section 2'\n" + " }\n" + " parallel nested\n" + "}\n" + "parallel steps\n" + "echo 'final'"));
}
story.j.buildAndAssertSuccess(job);
long millisDuration = job.getLastBuild().getDuration();
int time = new Random().nextInt((int) millisDuration);
WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
Thread.sleep(time);
logStart[0] = JenkinsRule.getLog(run);
nodesOut.clear();
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();
if (run.isBuilding()) {
story.j.waitForCompletion(run);
Assert.assertEquals(Result.SUCCESS, run.getResult());
} else {
verifyCompletedCleanly(story.j.jenkins, run);
}
assertIncludesNodes(nodesOut, run);
story.j.assertLogContains(logStart[0], run);
}
});
}
Aggregations