Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-26391] Prevent lazy loading operation when obtaining label i…
- Loading branch information
|
@@ -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{ |
|
|