Skip to content

Commit

Permalink
[JENKINS-25326] Added a test to reproduce JENKINS-25326
Browse files Browse the repository at this point in the history
Throttling doesn't work for projects in cloudbees-folder with Jenkins >= 1.536.
  • Loading branch information
ikedam committed Feb 21, 2016
1 parent ec7c123 commit d2f6ca4
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
15 changes: 14 additions & 1 deletion pom.xml
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.424</version>
<version>1.554</version>
</parent>

<artifactId>throttle-concurrents</artifactId>
Expand Down Expand Up @@ -113,6 +113,19 @@ THE SOFTWARE.
<version>2.0.1</version>
<type>jar</type>
</dependency>
<!-- Requires core 1.480.3 -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.9.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Expand Up @@ -29,6 +29,7 @@
import hudson.model.Node.Mode;
import hudson.plugins.throttleconcurrents.ThrottleJobProperty.NodeLabeledPair;
import hudson.plugins.throttleconcurrents.testutils.ExecutorWaterMarkRetentionStrategy;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.slaves.DumbSlave;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;
Expand All @@ -37,9 +38,12 @@
import java.util.Arrays;
import java.util.Collections;

import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.SleepBuilder;

import com.cloudbees.hudson.plugins.folder.Folder;

/**
* Tests that {@link ThrottleJobProperty} actually works for builds.
*/
Expand Down Expand Up @@ -80,8 +84,19 @@ private void setupSlave() throws Exception {
slave.setRetentionStrategy(waterMark);
}

/**
* setup security so that no one except SYSTEM has any permissions.
* should be called after {@link #setupSlave()}
*/
private void setupSecurity() {
jenkins.setSecurityRealm(createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
jenkins.setAuthorizationStrategy(auth);
}

public void testNoThrottling() throws Exception {
setupSlave();
setupSecurity();

FreeStyleProject p1 = createFreeStyleProject();
p1.setAssignedNode(slave);
Expand All @@ -102,6 +117,7 @@ public void testNoThrottling() throws Exception {

public void testThrottlingWithCategory() throws Exception {
setupSlave();
setupSecurity();
final String category = "category";

ThrottleJobProperty.DescriptorImpl descriptor
Expand Down Expand Up @@ -147,4 +163,56 @@ public void testThrottlingWithCategory() throws Exception {
// throttled, and only one build runs at the same time.
assertEquals(1, waterMark.getExecutorWaterMark());
}

@Bug(25326)
public void testThrottlingWithCategoryInFolder() throws Exception {
setupSlave();
setupSecurity();
final String category = "category";

ThrottleJobProperty.DescriptorImpl descriptor
= (ThrottleJobProperty.DescriptorImpl)jenkins.getDescriptor(ThrottleJobProperty.class);
descriptor.setCategories(Arrays.asList(
new ThrottleJobProperty.ThrottleCategory(
category,
1, // maxConcurrentPerNode
null, // maxConcurrentTotal
Collections.<NodeLabeledPair>emptyList()
)
));

Folder f1 = jenkins.createProject(Folder.class, "folder1");
FreeStyleProject p1 = f1.createProject(FreeStyleProject.class, "p");
p1.setAssignedNode(slave);
p1.addProperty(new ThrottleJobProperty(
null, // maxConcurrentPerNode
null, // maxConcurrentTotal
Arrays.asList(category), // categories
true, // throttleEnabled
"category", // throttleOption
ThrottleMatrixProjectOptions.DEFAULT
));
p1.getBuildersList().add(new SleepBuilder(SLEEP_TIME));

Folder f2 = jenkins.createProject(Folder.class, "folder2");
FreeStyleProject p2 = f2.createProject(FreeStyleProject.class, "p");
p2.setAssignedNode(slave);
p2.addProperty(new ThrottleJobProperty(
null, // maxConcurrentPerNode
null, // maxConcurrentTotal
Arrays.asList(category), // categories
true, // throttleEnabled
"category", // throttleOption
ThrottleMatrixProjectOptions.DEFAULT
));
p2.getBuildersList().add(new SleepBuilder(SLEEP_TIME));

p1.scheduleBuild2(0);
p2.scheduleBuild2(0);

waitUntilNoActivity();

// throttled, and only one build runs at the same time.
assertEquals(1, waterMark.getExecutorWaterMark());
}
}
Expand Up @@ -16,6 +16,7 @@
*/
package hudson.plugins.throttleconcurrents;

import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
Expand Down Expand Up @@ -358,7 +359,13 @@ private String configureLogger()
input.setValueAttribute(logger);
}
HtmlSelect select = form.getSelectByName("level");
HtmlOption option = select.getOptionByValue("fine");
HtmlOption option;
try {
option = select.getOptionByValue("fine");
} catch (ElementNotFoundException e) {
// gets upper case since Jenkins 1.519
option = select.getOptionByValue("FINE");
}
select.setSelectedAttribute(option, true);
break;
}
Expand Down

0 comments on commit d2f6ca4

Please sign in to comment.