Skip to content
Permalink
Browse files

[JENKINS-26391] Prevent lazy loading operation when obtaining label i…

…nformation.
  • Loading branch information...
christ66 committed Feb 16, 2015
1 parent 27dbc6b commit 7a2dc32cc3b309a4391ada820732a550d9d4badc
Showing with 27 additions and 2 deletions.
  1. +2 −2 core/src/main/java/hudson/model/Label.java
  2. +25 −0 test/src/test/java/hudson/model/NodeTest.java
@@ -374,7 +374,7 @@ public int getTiedJobCount() {
for (TopLevelItem topLevelItem : Jenkins.getInstance().getItemMap().values()) {
if (topLevelItem instanceof AbstractProject) {
final AbstractProject project = (AbstractProject) topLevelItem;
if (this.equals(project.getAssignedLabel())) {
if (this.name.equals(project.getAssignedLabelString())) {
result++;
}
}
@@ -389,7 +389,7 @@ public int getTiedJobCount() {
for (Item i : parent.getItems()) {
if (i instanceof AbstractProject) {
final AbstractProject project = (AbstractProject) i;
if (this.equals(project.getAssignedLabel())) {
if (this.name.equals(project.getAssignedLabelString())) {
result++;
}
}
@@ -24,6 +24,7 @@
package hudson.model;

import hudson.FilePath;
import hudson.maven.MavenModuleSet;
import hudson.model.Node.Mode;
import hudson.model.Queue.WaitingItem;
import hudson.model.labels.LabelAtom;
@@ -45,13 +46,17 @@
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.concurrent.Callable;

import jenkins.model.Jenkins;
import jenkins.security.QueueItemAuthenticatorConfiguration;
import org.acegisecurity.context.SecurityContextHolder;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.RunLoadCounter;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockQueueItemAuthenticator;
import org.jvnet.hudson.test.TestExtension;
@@ -237,6 +242,26 @@ public void testToComputer() throws Exception {
assertNull("Slave which is not added into Jenkins list nodes should not have assigned computer.", node.toComputer());
assertNotNull("Slave which is added into Jenkins list nodes should have assigned computer.", slave.toComputer());
}

@Issue("JENKINS-26391")
@Test
public void testGetAssignedLabelWithJobs() throws Exception {
final Node node = j.createOnlineSlave();
node.setLabelString("label1 label2");
MavenModuleSet mavenProject = j.createMavenProject();
mavenProject.setAssignedLabel(j.jenkins.getLabel("label1"));
RunLoadCounter.prepare(mavenProject);
j.assertBuildStatus(Result.FAILURE, mavenProject.scheduleBuild2(0).get());
Integer labelCount = RunLoadCounter.assertMaxLoads(mavenProject, 0, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return j.jenkins.getLabel("label1").getTiedJobCount();
}
});

assertEquals("Should have only one job tied to label.",
1, labelCount.intValue());
}

@TestExtension
public static class LabelFinderImpl extends LabelFinder{

0 comments on commit 7a2dc32

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