Skip to content

Commit b97764d

Browse files
authored
Flakes in DisconnectNodeCommandTest.disconnectNodeManyShouldSucceedWithCause (#10307)
1 parent 1418a40 commit b97764d

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

test/src/test/java/hudson/cli/DisconnectNodeCommandTest.java

+29-22
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import hudson.model.Computer;
3737
import hudson.slaves.DumbSlave;
3838
import hudson.slaves.OfflineCause;
39+
import java.util.ArrayList;
3940
import jenkins.model.Jenkins;
4041
import org.junit.Before;
4142
import org.junit.Rule;
@@ -187,32 +188,38 @@ public void disconnectNodeManyShouldSucceed() throws Exception {
187188

188189
@Test
189190
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+
}
202202

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");
203209
final CLICommandInvoker.Result result = command
204210
.authorizedTo(Computer.DISCONNECT, Jenkins.READ)
205-
.invokeWithArgs("aNode1", "aNode2", "aNode3", "-m", "aCause");
211+
.invokeWithArgs(args.toArray(String[]::new));
206212
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+
}
216223
}
217224

218225
@Test

0 commit comments

Comments
 (0)