Skip to content

Commit 06a4115

Browse files
authored
Delete builds in QueueTest to prevent Windows test failures (#26104)
* Remove noisy test logging from QueueTest No one is reading the test logs. They add megabytes to the output and may obscure useful messages. * Stop and delete builds 1 and 2 in QueueTest to prevent Windows test failures The Windows file system prevents cleanup of the builds and jobs directory while the test has them open. Stopping the builds and deleting them is enough to close the directory and allow it to be deleted. Testing done: * Before this change, testGetCauseOfBlockageForNonConcurrentFreestyle failed in about 50% of runs on my 7 different Windows agents * After this change, testGetCauseOfBlockageForNonConcurrentFreestyle passes all runs on my 7 different Windows agents
1 parent 8cfe02e commit 06a4115

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

test/src/test/java/hudson/model/QueueTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@
9090
import java.io.UncheckedIOException;
9191
import java.net.HttpURLConnection;
9292
import java.net.URI;
93-
import java.nio.charset.StandardCharsets;
94-
import java.nio.file.Files;
9593
import java.time.Duration;
9694
import java.util.ArrayList;
9795
import java.util.Arrays;
@@ -112,7 +110,6 @@
112110
import java.util.concurrent.atomic.AtomicBoolean;
113111
import java.util.concurrent.atomic.AtomicInteger;
114112
import java.util.function.Function;
115-
import java.util.logging.Level;
116113
import java.util.logging.Logger;
117114
import jenkins.model.BlockedBecauseOfBuildInProgress;
118115
import jenkins.model.Jenkins;
@@ -132,7 +129,6 @@
132129
import org.junit.jupiter.api.Test;
133130
import org.jvnet.hudson.test.Issue;
134131
import org.jvnet.hudson.test.JenkinsRule;
135-
import org.jvnet.hudson.test.LogRecorder;
136132
import org.jvnet.hudson.test.MockAuthorizationStrategy;
137133
import org.jvnet.hudson.test.MockQueueItemAuthenticator;
138134
import org.jvnet.hudson.test.SequenceLock;
@@ -150,8 +146,6 @@
150146
@WithJenkins
151147
public class QueueTest {
152148

153-
private final LogRecorder logging = new LogRecorder().record(Queue.class, Level.FINE);
154-
155149
private JenkinsRule r;
156150

157151
@BeforeEach
@@ -173,8 +167,6 @@ void persistence() throws Exception {
173167
assertNotNull(testProject.scheduleBuild2(0, new UserIdCause()));
174168
q.save();
175169

176-
System.out.println(Files.readString(r.jenkins.getRootDir().toPath().resolve("queue.xml"), StandardCharsets.UTF_8));
177-
178170
assertEquals(1, q.getItems().length);
179171
q.clear();
180172
assertEquals(0, q.getItems().length);
@@ -228,8 +220,6 @@ void persistence2() throws Exception {
228220
assertNotNull(testProject.scheduleBuild2(0, new UserIdCause()));
229221
q.save();
230222

231-
System.out.println(Files.readString(r.jenkins.getRootDir().toPath().resolve("queue.xml"), StandardCharsets.UTF_8));
232-
233223
assertEquals(1, q.getItems().length);
234224
q.clear();
235225
assertEquals(0, q.getItems().length);
@@ -372,7 +362,6 @@ Started by timer (2 times)
372362
Started by remote host 4.3.2.1 with note: test
373363
Started by remote host 1.2.3.4 with note: foo"""),
374364
"Build page should combine duplicates and show counts: " + buildPage);
375-
System.out.println(new XmlFile(new File(build.getRootDir(), "build.xml")).asString());
376365
}
377366

378367
@Issue("JENKINS-8790")
@@ -1243,7 +1232,22 @@ void testGetCauseOfBlockageForNonConcurrentFreestyle() throws Exception {
12431232

12441233
assertEquals(expected.getShortDescription(), actual.getShortDescription());
12451234
Queue.getInstance().doCancelItem(r.jenkins.getQueue().getBlockedItems().get(0).getId());
1246-
r.assertBuildStatusSuccess(r.waitForCompletion(build));
1235+
1236+
build.doStop(); // Stop build 1 early
1237+
r.waitForCompletion(build);
1238+
build.delete(); // Delete build 1
1239+
1240+
// Stop and delete build 2 if it is running. Seen running on slower Windows computers
1241+
if (t1.isBuilding()) {
1242+
FreeStyleBuild build2 = t1.getLastBuild();
1243+
build2.doStop();
1244+
r.waitForCompletion(build2);
1245+
build2.delete();
1246+
}
1247+
1248+
assertFalse(t1.isBuilding(), "Job unexpectedly building");
1249+
assertNull(t1.getQueueItem(), "Job unexpectedly has non-null entry in queue " + t1.getQueueItem());
1250+
assertFalse(t1.isInQueue(), "Job unexpectedly in queue");
12471251
}
12481252

12491253
@Test

0 commit comments

Comments
 (0)