Skip to content
Permalink
Browse files

Test cases to show [JENKINS-14278] occuring.

  • Loading branch information...
cjo9900 committed Jul 19, 2012
1 parent f8f0998 commit f26766b3eca5ebdd3388b1a0ba2fdb86c338c9fc
Showing with 134 additions and 11 deletions.
  1. +134 −11 src/test/java/hudson/plugins/parameterizedtrigger/test/TriggerBuilderTest.java
@@ -26,15 +26,23 @@
import hudson.model.Cause.UserCause;
import hudson.model.Project;
import hudson.model.Result;
import hudson.model.FreeStyleProject;
import hudson.plugins.parameterizedtrigger.AbstractBuildParameterFactory;
import hudson.plugins.parameterizedtrigger.AbstractBuildParameters;
import hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig;
import hudson.plugins.parameterizedtrigger.BlockingBehaviour;
import hudson.plugins.parameterizedtrigger.CounterBuildParameterFactory;
import hudson.plugins.parameterizedtrigger.TriggerBuilder;
import org.jvnet.hudson.test.Bug;

import hudson.matrix.TextAxis;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixRun;
import hudson.matrix.AxisList;

import java.util.Collections;
import java.util.List;
import java.io.IOException;

import org.jvnet.hudson.test.HudsonTestCase;
import com.google.common.collect.ImmutableList;
@@ -76,9 +84,45 @@ public void testOrderOfLogEntries() throws Exception {
assertEquals("project4 #1 completed. Result was SUCCESS", log.get(8));
assertEquals("project5 #1 completed. Result was SUCCESS", log.get(10));
assertEquals("project6 #1 completed. Result was SUCCESS", log.get(12));

}


public void testSubParameterBuilds() throws Exception {
hudson.setNumExecutors(10); // makes sure there are enough executors so that there are no deadlocks

FreeStyleProject p1 = createFreeStyleProject("project1");
createFreeStyleProject("project2");
createFreeStyleProject("project3");

///triggered from project 1
createFreeStyleProject("projectZ4");
createFreeStyleProject("projectZ5");
createFreeStyleProject("projectZ6");

Project<?, ?> triggerProject = createFreeStyleProject("projectA");

TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("project1"));
triggerBuilder.getConfigs().add(createTriggerConfig("project2"));
triggerBuilder.getConfigs().add(createTriggerConfig("project3"));

TriggerBuilder triggerBuilder2 = new TriggerBuilder(createTriggerConfig("projectZ4"));
triggerBuilder2.getConfigs().add(createTriggerConfig("projectZ5"));
triggerBuilder2.getConfigs().add(createTriggerConfig("projectZ6"));

p1.getBuildersList().add(triggerBuilder2);
triggerProject.getBuildersList().add(triggerBuilder);

triggerProject.scheduleBuild2(0, new UserCause()).get();

List<String> log = triggerProject.getLastBuild().getLog(20);
for (String string : log) {
System.out.println(string);
}
assertEquals("project1 #1 completed. Result was SUCCESS", log.get(2));
assertEquals("project2 #1 completed. Result was SUCCESS", log.get(4));
assertEquals("project3 #1 completed. Result was SUCCESS", log.get(6));
}

public void testWaitingForCompletion() throws Exception {
createFreeStyleProject("project1");
createFreeStyleProject("project2");
@@ -100,7 +144,7 @@ public void testWaitingForCompletion() throws Exception {
assertEquals("Waiting for the completion of project2", log.get(3));
assertEquals("Waiting for the completion of project3", log.get(5));
}

public void testNonBlockingTrigger() throws Exception {
createFreeStyleProject("project1");
createFreeStyleProject("project2");
@@ -119,23 +163,23 @@ public void testNonBlockingTrigger() throws Exception {
for (String string : log) {
System.out.println(string);
}

assertEquals("Triggering projects: project1, project2, project3", log.get(1));
}

public void testConsoleOutputWithCounterParameters() throws Exception{
createFreeStyleProject("project1");
createFreeStyleProject("project2");
createFreeStyleProject("project3");

Project<?,?> triggerProject = createFreeStyleProject();

BlockingBehaviour blockingBehaviour = new BlockingBehaviour(Result.FAILURE, Result.UNSTABLE, Result.FAILURE);
ImmutableList<AbstractBuildParameterFactory> buildParameter = ImmutableList.<AbstractBuildParameterFactory>of(new CounterBuildParameterFactory("0","2","1", "TEST=COUNT$COUNT"));
List<AbstractBuildParameters> emptyList = Collections.<AbstractBuildParameters>emptyList();

BlockableBuildTriggerConfig bBTConfig = new BlockableBuildTriggerConfig("project1, project2, project3", blockingBehaviour, buildParameter, emptyList);

triggerProject.getBuildersList().add(new TriggerBuilder(bBTConfig));

triggerProject.scheduleBuild2(0, new UserCause()).get();
@@ -144,7 +188,7 @@ public void testConsoleOutputWithCounterParameters() throws Exception{
for (String string : log) {
System.out.println(string);
}

assertEquals("project1 #1 completed. Result was SUCCESS", log.get(2));
assertEquals("project1 #2 completed. Result was SUCCESS", log.get(4));
assertEquals("project1 #3 completed. Result was SUCCESS", log.get(6));
@@ -156,7 +200,7 @@ public void testConsoleOutputWithCounterParameters() throws Exception{
assertEquals("project3 #3 completed. Result was SUCCESS", log.get(18));
}


public void testBlockingTriggerWithDisabledProjects() throws Exception {
createFreeStyleProject("project1");
Project<?, ?> p2 = createFreeStyleProject("project2");
@@ -178,6 +222,85 @@ public void testBlockingTriggerWithDisabledProjects() throws Exception {
assertEquals("Waiting for the completion of project1", log.get(1));
assertEquals("Skipping project2. The project is either disabled or the configuration has not been saved yet.", log.get(3));
assertEquals("Waiting for the completion of project3", log.get(4));


}


@Bug(14278)
public void testBlockingTriggerWithMatrixProject() throws Exception {

/* This test case will start a matrix project that is configured with 2 Axis
* each with two possible values giving 4 combinations.
* the build is configured with a TriggerBuilder which will block waiting for
* 6 other projects to complete.
*
* To allow this to run with no jobs being queued we need to have enogh exectors for all builds
* That is 1 + 4 + (4*6) = 29
* The minimun number of executors needed to allow test to run with queued builds would be
* 1 + 4 + 1 = 5 that is one exector for all of the builds that start others and
* and also a free executor to allow the queue to progress
*
* Set as 50 for first case.
*/

hudson.setNumExecutors(50);
createFreeStyleProject("project1");
createFreeStyleProject("project2");
createFreeStyleProject("project3");
createFreeStyleProject("project4");
createFreeStyleProject("project5");
createFreeStyleProject("project6");

MatrixProject matrixProject = createMatrixProject("matrixProject");

TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("project1"));
triggerBuilder.getConfigs().add(createTriggerConfig("project2"));
triggerBuilder.getConfigs().add(createTriggerConfig("project3"));
triggerBuilder.getConfigs().add(createTriggerConfig("project4"));
triggerBuilder.getConfigs().add(createTriggerConfig("project5"));
triggerBuilder.getConfigs().add(createTriggerConfig("project6"));

matrixProject.getBuildersList().add(triggerBuilder);

matrixProject.scheduleBuild2(0, new UserCause()).get();

List<String> log2 = matrixProject.getLastBuild().getLog(20);
System.out.println(log2);

List<MatrixRun> runs = matrixProject.getLastBuild().getRuns();

assertEquals(4,runs.size());
for (MatrixRun run : runs) {
List<String> log = run.getLog(20);
for (String string : log) {
System.out.println(string);
}
// checks are in two parts as we don't known exactly what build for each project will occur
assertStringContains(log.get(2), "project1");
assertStringContains(log.get(2), "completed. Result was SUCCESS");
assertStringContains(log.get(4), "project2");
assertStringContains(log.get(4), "completed. Result was SUCCESS");
assertStringContains(log.get(6), "project3");
assertStringContains(log.get(6), "completed. Result was SUCCESS");
assertStringContains(log.get(8), "project4");
assertStringContains(log.get(8), "completed. Result was SUCCESS");
assertStringContains(log.get(10), "project5");
assertStringContains(log.get(10), "completed. Result was SUCCESS");
assertStringContains(log.get(12), "project6");
assertStringContains(log.get(12), "completed. Result was SUCCESS");
}
}


@Override
protected MatrixProject createMatrixProject(String name) throws IOException {
MatrixProject p = super.createMatrixProject(name);
// set up 2x2 matrix
AxisList axes = new AxisList();
axes.add(new TextAxis("db","mysql","oracle"));
axes.add(new TextAxis("direction","north","south"));
p.setAxes(axes);

return p;
}
}

0 comments on commit f26766b

Please sign in to comment.
You can’t perform that action at this time.