Search in sources :

Example 1 with TestDurabilityHintProvider

use of org.jenkinsci.plugins.workflow.TestDurabilityHintProvider in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method createAndRunSleeperJob.

static WorkflowRun createAndRunSleeperJob(Jenkins jenkins, String jobName, FlowDurabilityHint durabilityHint) throws Exception {
    Item prev = jenkins.getItemByFullName(jobName);
    if (prev != null) {
        prev.delete();
    }
    WorkflowJob job = jenkins.createProject(WorkflowJob.class, jobName);
    CpsFlowDefinition def = new CpsFlowDefinition("node {\n " + "sleep 30 \n" + "} \n" + "echo 'I like cheese'\n", false);
    TestDurabilityHintProvider provider = Jenkins.getInstance().getExtensionList(TestDurabilityHintProvider.class).get(0);
    provider.registerHint(jobName, durabilityHint);
    job.setDefinition(def);
    WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
    // Hacky but we just need to ensure this can start up
    Thread.sleep(4000L);
    Assert.assertEquals(durabilityHint, run.getExecution().getDurabilityHint());
    Assert.assertEquals("sleep", run.getExecution().getCurrentHeads().get(0).getDisplayFunctionName());
    return run;
}
Also used : Item(hudson.model.Item) TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 2 with TestDurabilityHintProvider

use of org.jenkinsci.plugins.workflow.TestDurabilityHintProvider in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method testDurableAgainstCleanRestartResetsCleanlyPersistedFlag.

/**
 * Verify that our flag for whether or not a build was cleanly persisted gets reset when things happen.
 */
@Test
public void testDurableAgainstCleanRestartResetsCleanlyPersistedFlag() throws Exception {
    final String jobName = "durableAgainstClean";
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowJob job = story.j.jenkins.createProject(WorkflowJob.class, jobName);
            CpsFlowDefinition def = new CpsFlowDefinition("node {\n " + "  sleep 30 \n" + "  dir('nothing'){sleep 30;}\n" + "} \n" + "echo 'I like chese'\n", false);
            TestDurabilityHintProvider provider = Jenkins.get().getExtensionList(TestDurabilityHintProvider.class).get(0);
            provider.registerHint(jobName, FlowDurabilityHint.PERFORMANCE_OPTIMIZED);
            job.setDefinition(def);
            WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
            // Hacky but we just need to ensure this can start up
            Thread.sleep(2000L);
        }
    });
    story.addStepWithDirtyShutdown(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
            assert run.isBuilding();
            assert run.getResult() != Result.FAILURE;
            // Step completes
            Thread.sleep(35000);
            if (run.getExecution() instanceof CpsFlowExecution) {
                CpsFlowExecution exec = (CpsFlowExecution) run.getExecution();
                assert exec.persistedClean == null;
            }
        }
    });
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            // Just to allow time for basic async processes to finish.
            Thread.sleep(2000L);
            verifyFailedCleanly(story.j.jenkins, story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild());
        }
    });
}
Also used : Statement(org.junit.runners.model.Statement) TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 3 with TestDurabilityHintProvider

use of org.jenkinsci.plugins.workflow.TestDurabilityHintProvider in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method createAndRunBasicJob.

/**
 * Create and run a job with a semaphore and basic steps -- takes a semaphoreIndex in case you have multiple semaphores of the same name in one test.
 */
static WorkflowRun createAndRunBasicJob(Jenkins jenkins, String jobName, FlowDurabilityHint durabilityHint, int semaphoreIndex) throws Exception {
    WorkflowJob job = jenkins.createProject(WorkflowJob.class, jobName);
    CpsFlowDefinition def = new CpsFlowDefinition("node {\n " + "semaphore 'halt' \n" + "} \n" + "echo 'I like cheese'\n", false);
    TestDurabilityHintProvider provider = Jenkins.get().getExtensionList(TestDurabilityHintProvider.class).get(0);
    provider.registerHint(jobName, durabilityHint);
    job.setDefinition(def);
    WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
    SemaphoreStep.waitForStart("halt/" + semaphoreIndex, run);
    Assert.assertEquals(durabilityHint, run.getExecution().getDurabilityHint());
    Assert.assertFalse(run.getExecution().isComplete());
    Assert.assertFalse(((CpsFlowExecution) (run.getExecution())).done);
    if (durabilityHint.isPersistWithEveryStep()) {
        assertBaseStorageType(run.getExecution(), SimpleXStreamFlowNodeStorage.class);
    } else {
        assertBaseStorageType(run.getExecution(), BulkFlowNodeStorage.class);
    }
    Assert.assertEquals("semaphore", run.getExecution().getCurrentHeads().get(0).getDisplayFunctionName());
    return run;
}
Also used : TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 4 with TestDurabilityHintProvider

use of org.jenkinsci.plugins.workflow.TestDurabilityHintProvider in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method createAndRunSleeperJob.

private WorkflowRun createAndRunSleeperJob(Jenkins jenkins, String jobName, FlowDurabilityHint durabilityHint, boolean resumeBlocked) throws Exception {
    Item prev = jenkins.getItemByFullName(jobName);
    if (prev != null) {
        prev.delete();
    }
    WorkflowJob job = jenkins.createProject(WorkflowJob.class, jobName);
    job.setResumeBlocked(resumeBlocked);
    CpsFlowDefinition def = new CpsFlowDefinition("node {\n " + "sleep 30 \n" + "} \n" + "echo 'I like cheese'\n", false);
    TestDurabilityHintProvider provider = Jenkins.get().getExtensionList(TestDurabilityHintProvider.class).get(0);
    provider.registerHint(jobName, durabilityHint);
    job.setDefinition(def);
    WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
    story.j.waitForMessage("Sleeping for", run);
    Assert.assertFalse(run.getExecution().isComplete());
    Assert.assertFalse(((CpsFlowExecution) (run.getExecution())).done);
    Assert.assertEquals(durabilityHint, run.getExecution().getDurabilityHint());
    Assert.assertEquals("sleep", run.getExecution().getCurrentHeads().get(0).getDisplayFunctionName());
    return run;
}
Also used : Item(hudson.model.Item) TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 5 with TestDurabilityHintProvider

use of org.jenkinsci.plugins.workflow.TestDurabilityHintProvider in project workflow-cps-plugin by jenkinsci.

the class CpsScmFlowDefinitionTest method lightweight.

@Issue({ "JENKINS-33273", "JENKINS-63305" })
@Test
public void lightweight() throws Exception {
    sampleRepo.init();
    sampleRepo.write("flow.groovy", "echo 'version one'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=init");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    GitStep step = new GitStep(sampleRepo.toString());
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(step.createSCM(), "flow.groovy");
    def.setLightweight(true);
    TestDurabilityHintProvider provider = Jenkins.get().getExtensionList(TestDurabilityHintProvider.class).get(0);
    provider.registerHint("p", FlowDurabilityHint.PERFORMANCE_OPTIMIZED);
    p.setDefinition(def);
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, b.getExecution().getDurabilityHint());
    r.assertLogNotContains("Cloning the remote Git repository", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    r.assertLogContains("Obtained flow.groovy from git " + sampleRepo, b);
    r.assertLogContains("version one", b);
}
Also used : TestDurabilityHintProvider(org.jenkinsci.plugins.workflow.TestDurabilityHintProvider) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) GitStep(jenkins.plugins.git.GitStep) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

TestDurabilityHintProvider (org.jenkinsci.plugins.workflow.TestDurabilityHintProvider)5 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)5 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)5 Item (hudson.model.Item)2 Test (org.junit.Test)2 GitStep (jenkins.plugins.git.GitStep)1 Statement (org.junit.runners.model.Statement)1 Issue (org.jvnet.hudson.test.Issue)1