|
52 | 52 |
|
53 | 53 |
|
54 | 54 | import java.util.ArrayList;
|
| 55 | +import java.util.concurrent.Future; |
55 | 56 | import java.util.Collections;
|
56 | 57 | import java.util.List;
|
57 | 58 | import java.util.ListIterator;
|
|
70 | 71 | import static org.junit.Assert.assertEquals;
|
71 | 72 | import static org.junit.Assert.assertFalse;
|
72 | 73 | import static org.junit.Assert.assertNotNull;
|
| 74 | +import static org.junit.Assert.assertNull; |
| 75 | +import static org.junit.Assert.assertArrayEquals; |
73 | 76 | import static org.junit.Assert.assertTrue;
|
74 | 77 | import static org.mockito.ArgumentMatchers.any;
|
75 | 78 | import static org.mockito.Mockito.when;
|
76 | 79 |
|
| 80 | + |
77 | 81 | public class TriggerBuilderTest {
|
78 | 82 |
|
79 | 83 | @Rule
|
@@ -224,6 +228,34 @@ public void testNonBlockingTrigger() throws Exception {
|
224 | 228 | "Triggering projects: project1, project2, project3");
|
225 | 229 | }
|
226 | 230 |
|
| 231 | + @Test |
| 232 | + public void testCancelsDownstreamBuildWhenInterrupted() throws Exception{ |
| 233 | + r.jenkins.setNumExecutors(1); // the downstream-project would be in the build queue |
| 234 | + |
| 235 | + FreeStyleProject triggerProject = r.createFreeStyleProject("upstream-project"); |
| 236 | + FreeStyleProject downstreamProject = r.createFreeStyleProject("downstream-project"); |
| 237 | + |
| 238 | + TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("downstream-project")); |
| 239 | + |
| 240 | + triggerProject.getBuildersList().add(triggerBuilder); |
| 241 | + |
| 242 | + QueueTaskFuture<FreeStyleBuild> parentBuild = triggerProject.scheduleBuild2(0); |
| 243 | + parentBuild.waitForStart(); |
| 244 | + |
| 245 | + // Now cancel the trigger project and let it finishes |
| 246 | + triggerProject.getLastBuild().getExecutor().interrupt(); |
| 247 | + parentBuild.get(); |
| 248 | + |
| 249 | + assertLines(triggerProject.getLastBuild(), |
| 250 | + "Waiting for the completion of downstream-project", |
| 251 | + "Build aborting: cancelling queued project downstream-project", |
| 252 | + "Build was aborted", |
| 253 | + "Finished: ABORTED" |
| 254 | + ); |
| 255 | + assertNull("No downstream build has been run", downstreamProject.getLastBuild()); |
| 256 | + assertEquals("No build left in queue", 0, r.jenkins.getQueue().countBuildableItems()); |
| 257 | + } |
| 258 | + |
227 | 259 | @Test
|
228 | 260 | public void testConsoleOutputWithCounterParameters() throws Exception{
|
229 | 261 | r.createFreeStyleProject("project1");
|
|
0 commit comments