Skip to content

Commit

Permalink
Apply phrasing changes on the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yashpal2104 committed Dec 23, 2024
1 parent b15026f commit c680228
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static org.junit.Assert.*;

import hudson.model.Computer;
import hudson.model.Node;
import hudson.plugins.parameterizedtrigger.AbstractBuildParameters;
import hudson.slaves.DumbSlave;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -41,7 +43,7 @@ public void getParameters_withAllNodesOnline() throws Exception {

List<AbstractBuildParameters> params = factory.getParameters(null, j.createTaskListener());

// trigger build on Jenkins (built-in) included in params.size() so added 1 in expected
// Parameters should include 2 agents and the Jenkins controller (built-in)
assertEquals(3, params.size());
}

Expand All @@ -54,7 +56,8 @@ public void getParameters_withAllNodesOffline() throws Exception {
Objects.requireNonNull(node2.toComputer()).disconnect(null);

List<AbstractBuildParameters> params = factory.getParameters(null, j.createTaskListener());
// trigger build on Jenkins (built-in)
// Parameters should only include the controller, since 2 agents are offline
// AllNodes factory only returns online agents with 1 or more executors
assertEquals(1, params.size());
}

Expand All @@ -66,7 +69,7 @@ public void getParameters_withMixedNodeStates() throws Exception {
Objects.requireNonNull(node2.toComputer()).disconnect(null);

List<AbstractBuildParameters> params = factory.getParameters(null, j.createTaskListener());
// trigger build on Jenkins (built-in)
// Parameters should include the controller and the 1 online agent
assertEquals(2, params.size());
}

Expand All @@ -81,4 +84,28 @@ public void getParameters_withNoNodes() throws Exception {

assertTrue(params.isEmpty());
}

@Test
public void getParameters_setOneExecutorAgentToZero() throws Exception {
DumbSlave node1 = j.createOnlineSlave();
DumbSlave node2 = j.createOnlineSlave();

node1.setNumExecutors(0);

List<AbstractBuildParameters> params = factory.getParameters(null, j.createTaskListener());

// node1 will not be able to execute any builds but it will be included in the list of nodes
assertEquals(3, params.size());

// Create a list of nodes that can execute builds
List<Node> buildableNodes = new ArrayList<>();
for (Computer c : Jenkins.get().getComputers()) {
Node n = c.getNode();
if (n != null && c.isOnline() && c.getNumExecutors() > 0) {
buildableNodes.add(n);
}
}
// Check that the number of buildable nodes is equal to the number of parameters
assertEquals(buildableNodes.size(), params.size());
}
}

0 comments on commit c680228

Please sign in to comment.