|
36 | 36 | import hudson.model.Computer;
|
37 | 37 | import hudson.slaves.DumbSlave;
|
38 | 38 | import hudson.slaves.OfflineCause;
|
| 39 | +import java.util.ArrayList; |
39 | 40 | import jenkins.model.Jenkins;
|
40 | 41 | import org.junit.Before;
|
41 | 42 | import org.junit.Rule;
|
@@ -187,32 +188,38 @@ public void disconnectNodeManyShouldSucceed() throws Exception {
|
187 | 188 |
|
188 | 189 | @Test
|
189 | 190 | public void disconnectNodeManyShouldSucceedWithCause() throws Exception {
|
190 |
| - DumbSlave slave1 = j.createSlave("aNode1", "", null); |
191 |
| - DumbSlave slave2 = j.createSlave("aNode2", "", null); |
192 |
| - DumbSlave slave3 = j.createSlave("aNode3", "", null); |
193 |
| - slave1.toComputer().waitUntilOnline(); |
194 |
| - assertThat(slave1.toComputer().isOnline(), equalTo(true)); |
195 |
| - assertThat(slave1.toComputer().getOfflineCause(), equalTo(null)); |
196 |
| - slave2.toComputer().waitUntilOnline(); |
197 |
| - assertThat(slave2.toComputer().isOnline(), equalTo(true)); |
198 |
| - assertThat(slave2.toComputer().getOfflineCause(), equalTo(null)); |
199 |
| - slave3.toComputer().waitUntilOnline(); |
200 |
| - assertThat(slave3.toComputer().isOnline(), equalTo(true)); |
201 |
| - assertThat(slave3.toComputer().getOfflineCause(), equalTo(null)); |
| 191 | + int n = 3; |
| 192 | + var agents = new ArrayList<DumbSlave>(); |
| 193 | + for (int i = 1; i <= n; i++) { |
| 194 | + agents.add(j.createSlave("aNode" + i, "", null)); |
| 195 | + } |
| 196 | + for (var agent : agents) { |
| 197 | + var computer = agent.toComputer(); |
| 198 | + computer.waitUntilOnline(); |
| 199 | + assertThat(computer.isOnline(), equalTo(true)); |
| 200 | + assertThat(computer.getOfflineCause(), equalTo(null)); |
| 201 | + } |
202 | 202 |
|
| 203 | + var args = new ArrayList<String>(); |
| 204 | + for (var agent : agents) { |
| 205 | + args.add(agent.getNodeName()); |
| 206 | + } |
| 207 | + args.add("-m"); |
| 208 | + args.add("aCause"); |
203 | 209 | final CLICommandInvoker.Result result = command
|
204 | 210 | .authorizedTo(Computer.DISCONNECT, Jenkins.READ)
|
205 |
| - .invokeWithArgs("aNode1", "aNode2", "aNode3", "-m", "aCause"); |
| 211 | + .invokeWithArgs(args.toArray(String[]::new)); |
206 | 212 | assertThat(result, succeededSilently());
|
207 |
| - assertThat(slave1.toComputer().isOffline(), equalTo(true)); |
208 |
| - assertThat(slave1.toComputer().getOfflineCause(), instanceOf(OfflineCause.ByCLI.class)); |
209 |
| - assertThat(((OfflineCause.ByCLI) slave1.toComputer().getOfflineCause()).message, equalTo("aCause")); |
210 |
| - assertThat(slave2.toComputer().isOffline(), equalTo(true)); |
211 |
| - assertThat(slave2.toComputer().getOfflineCause(), instanceOf(OfflineCause.ByCLI.class)); |
212 |
| - assertThat(((OfflineCause.ByCLI) slave2.toComputer().getOfflineCause()).message, equalTo("aCause")); |
213 |
| - assertThat(slave3.toComputer().isOffline(), equalTo(true)); |
214 |
| - assertThat(slave3.toComputer().getOfflineCause(), instanceOf(OfflineCause.ByCLI.class)); |
215 |
| - assertThat(((OfflineCause.ByCLI) slave3.toComputer().getOfflineCause()).message, equalTo("aCause")); |
| 213 | + for (var agent : agents) { |
| 214 | + var computer = agent.toComputer(); |
| 215 | + assertThat(computer.isOffline(), equalTo(true)); |
| 216 | + var cause = computer.getOfflineCause(); |
| 217 | + if (cause instanceof OfflineCause.ByCLI cliCause) { |
| 218 | + assertThat(cliCause.message, equalTo("aCause")); |
| 219 | + } else { |
| 220 | + assertThat("seen occasionally in CI", cause, instanceOf(OfflineCause.ChannelTermination.class)); |
| 221 | + } |
| 222 | + } |
216 | 223 | }
|
217 | 224 |
|
218 | 225 | @Test
|
|
0 commit comments