MaintainCanTakeStrengtheningTest is flaky (#8429)

This commit is contained in:
Basil Crow authored and GitHub committed 2023-08-25 11:27:38 +01:00
1 parent 0bd2e4a528
commit d6c8daaa9a
1 file changed
+9 -11
@@ -4,13 +4,13 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Label;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.slaves.DumbSlave;
import hudson.slaves.NodeProperty;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.junit.Rule;
import org.junit.Test;
@@ -26,7 +26,7 @@ public class MaintainCanTakeStrengtheningTest {
@Rule
public LoggerRule logging = new LoggerRule().record(Node.class.getName(), Level.ALL).capture(100);
private QueueTaskFuture scheduleBuild(String name, String label) throws Exception {
private QueueTaskFuture<FreeStyleBuild> scheduleBuild(String name, String label) throws Exception {
FreeStyleProject project = r.createFreeStyleProject(name);
project.setAssignedLabel(Label.get(label));
@@ -44,15 +44,9 @@ public class MaintainCanTakeStrengtheningTest {
r.createOnlineSlave(Label.get("good"));
// Only the good ones will be run and the latest doesn't get hung because of the second
QueueTaskFuture[] taskFuture = new QueueTaskFuture[3];
taskFuture[0] = scheduleBuild("good1", "good");
taskFuture[1] = scheduleBuild("theFaultyOne", "faulty");
taskFuture[2] = scheduleBuild("good2", "good");
// Wait for a while until the good ones start, no need to wait for their completion to guarantee
// the fix works
taskFuture[0].getStartCondition().get(15, TimeUnit.SECONDS);
taskFuture[2].getStartCondition().get(15, TimeUnit.SECONDS);
FreeStyleBuild good1 = scheduleBuild("good1", "good").waitForStart();
scheduleBuild("theFaultyOne", "faulty");
FreeStyleBuild good2 = scheduleBuild("good2", "good").waitForStart();
// The faulty one is the only one in the queue
assertThat(r.getInstance().getQueue().getBuildableItems().size(), equalTo(1));
@@ -60,6 +54,10 @@ public class MaintainCanTakeStrengtheningTest {
// The new error is shown in the logs
assertThat(logging.getMessages(), hasItem(String.format("Exception evaluating if the node '%s' can take the task '%s'", faultyAgent.getDisplayName(), "theFaultyOne")));
// Tear down
r.assertBuildStatusSuccess(r.waitForCompletion(good1));
r.assertBuildStatusSuccess(r.waitForCompletion(good2));
}
/**