From d6c8daaa9a645ab44e9d79f32e5d4e6a08fc67a4 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 25 Aug 2023 03:27:38 -0700 Subject: [PATCH] `MaintainCanTakeStrengtheningTest` is flaky (#8429) --- .../MaintainCanTakeStrengtheningTest.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/src/test/java/hudson/model/queue/MaintainCanTakeStrengtheningTest.java b/test/src/test/java/hudson/model/queue/MaintainCanTakeStrengtheningTest.java index a9c64db975..c9deee7aac 100644 --- a/test/src/test/java/hudson/model/queue/MaintainCanTakeStrengtheningTest.java +++ b/test/src/test/java/hudson/model/queue/MaintainCanTakeStrengtheningTest.java @@ -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 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)); } /**