Flakes in `DisconnectNodeCommandTest.disconnectNodeManyShouldSucceedWithCause` (#10307)

This commit is contained in:
Jesse Glick 2025-02-21 02:39:07 -05:00 committed by GitHub
parent 1418a40288
commit b97764d3fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 22 deletions

View File

@ -36,6 +36,7 @@ import static org.hamcrest.Matchers.not;
import hudson.model.Computer; import hudson.model.Computer;
import hudson.slaves.DumbSlave; import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause; import hudson.slaves.OfflineCause;
import java.util.ArrayList;
import jenkins.model.Jenkins; import jenkins.model.Jenkins;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -187,32 +188,38 @@ public class DisconnectNodeCommandTest {
@Test @Test
public void disconnectNodeManyShouldSucceedWithCause() throws Exception { public void disconnectNodeManyShouldSucceedWithCause() throws Exception {
DumbSlave slave1 = j.createSlave("aNode1", "", null); int n = 3;
DumbSlave slave2 = j.createSlave("aNode2", "", null); var agents = new ArrayList<DumbSlave>();
DumbSlave slave3 = j.createSlave("aNode3", "", null); for (int i = 1; i <= n; i++) {
slave1.toComputer().waitUntilOnline(); agents.add(j.createSlave("aNode" + i, "", null));
assertThat(slave1.toComputer().isOnline(), equalTo(true)); }
assertThat(slave1.toComputer().getOfflineCause(), equalTo(null)); for (var agent : agents) {
slave2.toComputer().waitUntilOnline(); var computer = agent.toComputer();
assertThat(slave2.toComputer().isOnline(), equalTo(true)); computer.waitUntilOnline();
assertThat(slave2.toComputer().getOfflineCause(), equalTo(null)); assertThat(computer.isOnline(), equalTo(true));
slave3.toComputer().waitUntilOnline(); assertThat(computer.getOfflineCause(), equalTo(null));
assertThat(slave3.toComputer().isOnline(), equalTo(true)); }
assertThat(slave3.toComputer().getOfflineCause(), equalTo(null));
var args = new ArrayList<String>();
for (var agent : agents) {
args.add(agent.getNodeName());
}
args.add("-m");
args.add("aCause");
final CLICommandInvoker.Result result = command final CLICommandInvoker.Result result = command
.authorizedTo(Computer.DISCONNECT, Jenkins.READ) .authorizedTo(Computer.DISCONNECT, Jenkins.READ)
.invokeWithArgs("aNode1", "aNode2", "aNode3", "-m", "aCause"); .invokeWithArgs(args.toArray(String[]::new));
assertThat(result, succeededSilently()); assertThat(result, succeededSilently());
assertThat(slave1.toComputer().isOffline(), equalTo(true)); for (var agent : agents) {
assertThat(slave1.toComputer().getOfflineCause(), instanceOf(OfflineCause.ByCLI.class)); var computer = agent.toComputer();
assertThat(((OfflineCause.ByCLI) slave1.toComputer().getOfflineCause()).message, equalTo("aCause")); assertThat(computer.isOffline(), equalTo(true));
assertThat(slave2.toComputer().isOffline(), equalTo(true)); var cause = computer.getOfflineCause();
assertThat(slave2.toComputer().getOfflineCause(), instanceOf(OfflineCause.ByCLI.class)); if (cause instanceof OfflineCause.ByCLI cliCause) {
assertThat(((OfflineCause.ByCLI) slave2.toComputer().getOfflineCause()).message, equalTo("aCause")); assertThat(cliCause.message, equalTo("aCause"));
assertThat(slave3.toComputer().isOffline(), equalTo(true)); } else {
assertThat(slave3.toComputer().getOfflineCause(), instanceOf(OfflineCause.ByCLI.class)); assertThat("seen occasionally in CI", cause, instanceOf(OfflineCause.ChannelTermination.class));
assertThat(((OfflineCause.ByCLI) slave3.toComputer().getOfflineCause()).message, equalTo("aCause")); }
}
} }
@Test @Test