9090import java .io .UncheckedIOException ;
9191import java .net .HttpURLConnection ;
9292import java .net .URI ;
93- import java .nio .charset .StandardCharsets ;
94- import java .nio .file .Files ;
9593import java .time .Duration ;
9694import java .util .ArrayList ;
9795import java .util .Arrays ;
112110import java .util .concurrent .atomic .AtomicBoolean ;
113111import java .util .concurrent .atomic .AtomicInteger ;
114112import java .util .function .Function ;
115- import java .util .logging .Level ;
116113import java .util .logging .Logger ;
117114import jenkins .model .BlockedBecauseOfBuildInProgress ;
118115import jenkins .model .Jenkins ;
132129import org .junit .jupiter .api .Test ;
133130import org .jvnet .hudson .test .Issue ;
134131import org .jvnet .hudson .test .JenkinsRule ;
135- import org .jvnet .hudson .test .LogRecorder ;
136132import org .jvnet .hudson .test .MockAuthorizationStrategy ;
137133import org .jvnet .hudson .test .MockQueueItemAuthenticator ;
138134import org .jvnet .hudson .test .SequenceLock ;
150146@ WithJenkins
151147public 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