From c680228cef78615ab32fd87b6f1da499923153e0 Mon Sep 17 00:00:00 2001 From: Yash Pal Date: Mon, 23 Dec 2024 19:44:50 +0530 Subject: [PATCH] Apply phrasing changes on the comments --- .../AllNodesBuildParameterFactoryTest.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/parameterizedtrigger/AllNodesBuildParameterFactoryTest.java b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/parameterizedtrigger/AllNodesBuildParameterFactoryTest.java index 8d2ec6b..d7742e1 100644 --- a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/parameterizedtrigger/AllNodesBuildParameterFactoryTest.java +++ b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/parameterizedtrigger/AllNodesBuildParameterFactoryTest.java @@ -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; @@ -41,7 +43,7 @@ public void getParameters_withAllNodesOnline() throws Exception { List 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()); } @@ -54,7 +56,8 @@ public void getParameters_withAllNodesOffline() throws Exception { Objects.requireNonNull(node2.toComputer()).disconnect(null); List 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()); } @@ -66,7 +69,7 @@ public void getParameters_withMixedNodeStates() throws Exception { Objects.requireNonNull(node2.toComputer()).disconnect(null); List 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()); } @@ -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 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 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()); + } }