-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-69751] Add sorting for blocked projects (#69)
* Add sorting for blocked projects * [JENKINS-69751]: Wrote a test for AdvancedQueueSorter.sortBlockedItems(List<Queue.BlockedItem> blockedItems) * Format sources before merge with master * Format source files before merge * Remove unused imports * Do not lose icon impl * Do not lose spotbugs exclusions --------- Co-authored-by: Mark Waite <[email protected]> Co-authored-by: Simon Sohrt <[email protected]>
- Loading branch information
1 parent
38b7de9
commit 4459da7
Showing
4 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/jenkins/advancedqueue/test/SortBlockedItemsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package jenkins.advancedqueue.test; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Queue; | ||
import hudson.tasks.BuildTrigger; | ||
import jenkins.advancedqueue.testutil.ExpectedItem; | ||
import jenkins.advancedqueue.testutil.TestRunListener; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
public class SortBlockedItemsTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
@LocalData | ||
public void blockedItemsAreSortedByPriority() throws Exception { | ||
// Priority value is configured in jenkins.advancedqueue.PrioritySorterConfiguration. Value is 2. | ||
FreeStyleProject upstreamProject = j.createFreeStyleProject("upstreamProject"); | ||
// Priority value is configured in jenkins.advancedqueue.PrioritySorterConfiguration. Value is 1. | ||
FreeStyleProject downstreamProject = j.createFreeStyleProject("downstreamProject"); | ||
upstreamProject.setBlockBuildWhenDownstreamBuilding(true); | ||
downstreamProject.setBlockBuildWhenUpstreamBuilding(true); | ||
upstreamProject.getPublishersList().add(new BuildTrigger(downstreamProject.getName(), true)); | ||
// Expected build sequence: downstreamProject#1 -> upstreamProject#1 -> downstreamProject#2 | ||
TestRunListener.init( | ||
new ExpectedItem(downstreamProject.getName(), 1), | ||
new ExpectedItem(upstreamProject.getName(), 2), | ||
new ExpectedItem(downstreamProject.getName(), 1)); | ||
|
||
j.jenkins.rebuildDependencyGraph(); | ||
|
||
// Locking makes sure that the queue sees both builds at the same time even though upstreamProject entered the | ||
// queue first | ||
Queue.withLock(() -> { | ||
j.jenkins.getQueue().schedule2(upstreamProject, 0); | ||
j.jenkins.getQueue().schedule2(downstreamProject, 0); | ||
j.jenkins.getQueue().maintain(); | ||
}); | ||
j.waitUntilNoActivity(); | ||
|
||
TestRunListener.assertStartedItems(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...s/advancedqueue/test/SortBlockedItemsTest/jenkins.advancedqueue.PriorityConfiguration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<jenkins.advancedqueue.PriorityConfiguration plugin="[email protected]"> | ||
<jobGroups class="linked-list"> | ||
<jenkins.advancedqueue.JobGroup> | ||
<id>0</id> | ||
<priority>2</priority> | ||
<view>All</view> | ||
<runExclusive>false</runExclusive> | ||
<useJobFilter>true</useJobFilter> | ||
<jobPattern>upstreamProject</jobPattern> | ||
<usePriorityStrategies>false</usePriorityStrategies> | ||
<priorityStrategies> | ||
</priorityStrategies> | ||
</jenkins.advancedqueue.JobGroup> | ||
<jenkins.advancedqueue.JobGroup> | ||
<id>1</id> | ||
<priority>1</priority> | ||
<view>All</view> | ||
<runExclusive>false</runExclusive> | ||
<useJobFilter>true</useJobFilter> | ||
<jobPattern>downstreamProject</jobPattern> | ||
<usePriorityStrategies>false</usePriorityStrategies> | ||
<priorityStrategies> | ||
</priorityStrategies> | ||
</jenkins.advancedqueue.JobGroup> | ||
</jobGroups> | ||
</jenkins.advancedqueue.PriorityConfiguration> |
8 changes: 8 additions & 0 deletions
8
...ncedqueue/test/SortBlockedItemsTest/jenkins.advancedqueue.PrioritySorterConfiguration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<jenkins.advancedqueue.PrioritySorterConfiguration> | ||
<allowPriorityOnJobs>true</allowPriorityOnJobs> | ||
<strategy class="jenkins.advancedqueue.sorter.strategy.AbsoluteStrategy">> | ||
<numberOfPriorities>2</numberOfPriorities> | ||
<defaultPriority>1</defaultPriority> | ||
</strategy> | ||
</jenkins.advancedqueue.PrioritySorterConfiguration> |