Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix tests for JENKINS-13554
  • Loading branch information
olivergondza committed Dec 15, 2017
1 parent 9e4d3bf commit d3e68d0
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions src/test/java/hudson/matrix/MatrixProjectTest.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.matrix;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.cli.CLICommandInvoker;
import hudson.cli.DeleteBuildsCommand;
Expand Down Expand Up @@ -93,6 +94,8 @@
import java.util.Map;
import java.util.Set;
import jenkins.model.Jenkins;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;

import org.junit.Rule;
Expand Down Expand Up @@ -568,34 +571,61 @@ public void dontRunOnExclusiveSlave() throws Exception {
@Test @Issue("JENKINS-13554")
public void deletedLockedParentBuild() throws Exception {
MatrixProject p = j.jenkins.createProject(MatrixProject.class, "project");
p.setAxes(new AxisList(new TextAxis("AXIS", "VALUE")));
MatrixBuild build = p.scheduleBuild2(0).get();
MatrixConfiguration c = p.getItem("AXIS=VALUE");
p.setAxes(new AxisList(new TextAxis("AXIS", "1", "2")));
MatrixBuild codeDelete = p.scheduleBuild2(0).get();
MatrixBuild uiDelete = p.scheduleBuild2(0).get();
p.scheduleBuild2(0).get();
MatrixConfiguration c = p.getItem("AXIS=1");
c.getLastBuild().delete(); // Punch a hole to matrix locking older builds

assertEquals(3, p.getBuilds().size());
assertEquals(2, c.getBuilds().size());

//j.interactiveBreak();

build.keepLog();
// UI delete
JenkinsRule.WebClient wc = j.createWebClient();
HtmlPage deletePage = wc.getPage(uiDelete).getAnchorByText("Delete Build").click();

build.delete();
assertThat(deletePage.getWebResponse().getContentAsString(), containsString("Warning: #3 depends on this."));

assertEquals("parent build is deleted", 0, p.getBuilds().size());
assertEquals("child build is deleted", 0, c.getBuilds().size());
j.submit(deletePage.getForms().get(1));
//deletePage.getForms().get(1).getInputByValue("Yes").click();
assertEquals(2, p.getBuilds().size());

// Code delete
codeDelete.delete();
assertEquals(1, p.getBuilds().size());
}

@Test @Issue("JENKINS-13554")
public void deletedParentBuildWithLockedChildren() throws Exception {
public void deletedLockedChildrenBuild() throws Exception {
MatrixProject p = j.jenkins.createProject(MatrixProject.class, "project");
p.setAxes(new AxisList(new TextAxis("AXIS", "VALUE")));
MatrixBuild build = p.scheduleBuild2(0).get();
p.setAxes(new AxisList(new TextAxis("AXIS", "1", "2")));
p.scheduleBuild2(0).get();
p.scheduleBuild2(0).get();
p.scheduleBuild2(0).get();
MatrixConfiguration c = p.getItem("AXIS=1");
c.getLastBuild().delete(); // Punch a hole to matrix locking older builds
MatrixRun uiDelete = c.getBuildByNumber(2);
MatrixRun codeDelete = c.getBuildByNumber(1);

MatrixConfiguration c = p.getItem("AXIS=VALUE");
assertEquals(3, p.getBuilds().size());
assertEquals(2, c.getBuilds().size());

// UI delete
JenkinsRule.WebClient wc = j.createWebClient();
HtmlPage deletePage = wc.getPage(uiDelete).getAnchorByText("Delete Build").click();

c.getBuildByNumber(2).delete(); // delete newest run
assertNotNull(c.getBuildByNumber(1).getWhyKeepLog());
assertThat(deletePage.getWebResponse().getContentAsString(), containsString("Warning: #3 depends on this."));

build.delete();
j.submit(deletePage.getForms().get(1));
//deletePage.getForms().get(1).getInputByValue("Yes").click();
assertEquals(2, p.getBuilds().size());

assertEquals("last parent build should be kept", 1, p.getBuilds().size());
assertEquals("child builds are deleted", 0, c.getBuilds().size());
// Code delete
codeDelete.delete();
assertEquals(1, p.getBuilds().size());
}

@Test @Issue("JENKINS-13554")
Expand Down

0 comments on commit d3e68d0

Please sign in to comment.