Skip to content

Commit

Permalink
Test now includes a restart
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Sep 17, 2016
1 parent 0835001 commit 85a1d22
Showing 1 changed file with 38 additions and 10 deletions.
Expand Up @@ -3,28 +3,56 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.junit.runners.model.Statement;
import org.jvnet.hudson.test.RestartableJenkinsRule;

/**
* @author Kohsuke Kawaguchi
* @see "doc/step-in-groovy.md"
*/
public class StepInGroovyTest {
@Rule
public JenkinsRule j = new JenkinsRule();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();

/**
* Invokes helloWorldGroovy.groovy in resources/stepsInGroovy and make sure that works
* Invokes helloWorldGroovy.groovy in resources/stepsInGroovy and make sure that works.
*
* Restart Jenkins in the middle to make sure the resurrection works as expected.
*/
@Test
public void helloWorld() throws Exception {
WorkflowJob p = j.createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition("helloWorldGroovy('Duke') { echo 'Hello body' }"));
WorkflowRun b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
j.assertLogContains("Hello Duke",b);
j.assertLogContains("Hello body",b);
j.assertLogContains("Good bye Duke",b);
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(
"helloWorldGroovy('Duke') {\n" +
"echo 'Hello body'\n"+
"semaphore 'restart'\n"+
"echo 'Good bye body'\n"+
"}"));
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
SemaphoreStep.waitForStart("restart/1", b);
story.j.waitForMessage("Hello body",b);
story.j.assertLogContains("Hello Duke",b);
story.j.assertLogContains("Hello body",b);
}
});
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.getItemByFullName("demo", WorkflowJob.class);
WorkflowRun b = p.getLastBuild();
SemaphoreStep.success("restart/1", null);
story.j.waitForCompletion(b);

story.j.assertLogContains("Hello Duke",b);
story.j.assertLogContains("Hello body",b);
story.j.assertLogContains("Good bye body",b);
story.j.assertLogContains("Good bye Duke",b);
}
});
}
}

0 comments on commit 85a1d22

Please sign in to comment.