Skip to content

Commit

Permalink
[JENKINS-34716] Verifying doPolling in a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed May 5, 2017
1 parent a8c5b5f commit 7ecd985
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<jenkins-test-harness.version>2.19</jenkins-test-harness.version>
<no-test-jar>false</no-test-jar>
<workflow-support-plugin.version>2.2</workflow-support-plugin.version>
<scm-api-plugin.version>2.1.1</scm-api-plugin.version>
<git-plugin.version>3.2.0</git-plugin.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -109,5 +111,31 @@
<version>2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>${scm-api-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>${scm-api-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>${git-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>${git-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import hudson.model.Result;
import hudson.plugins.git.GitSCM;
import hudson.security.WhoAmI;
import hudson.triggers.SCMTrigger;
import jenkins.plugins.git.GitSampleRepoRule;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class WorkflowJobTest {

@Rule public JenkinsRule j = new JenkinsRule();
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

@Issue("JENKINS-40255")
@Test public void getSCM() throws Exception {
Expand Down Expand Up @@ -42,6 +48,26 @@ public class WorkflowJobTest {
assertEquals("Expecting zero SCMs",0, p.getSCMs().size());
}

@Issue("JENKINS-34716")
@Test public void polling() throws Exception {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "echo 'first version'");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "-m", "init");
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.addTrigger(new SCMTrigger(""));
p.setDefinition(new CpsScmFlowDefinition(new GitSCM(sampleRepo.toString()), "Jenkinsfile"));
j.assertLogContains("first version", j.buildAndAssertSuccess(p));
sampleRepo.write("Jenkinsfile", "echo 'second version'");
sampleRepo.git("commit", "-a", "-m", "init");
j.jenkins.setQuietPeriod(0);
j.createWebClient().getPage(new WebRequest(j.createWebClient().createCrumbedUrl(p.getUrl() + "polling"), HttpMethod.POST));
j.waitUntilNoActivity();
WorkflowRun b2 = p.getLastBuild();
assertEquals(2, b2.getNumber());
j.assertLogContains("second version", b2);
}

@Test
public void addAction() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
Expand Down

0 comments on commit 7ecd985

Please sign in to comment.