|
10 | 10 | import hudson.model.queue.SubTask;
|
11 | 11 | import hudson.slaves.ComputerLauncher;
|
12 | 12 | import jenkins.model.Jenkins;
|
| 13 | +import org.jenkinsci.plugins.workflow.job.WorkflowJob; |
| 14 | +import org.jenkinsci.plugins.workflow.job.WorkflowRun; |
13 | 15 | import org.junit.Before;
|
14 | 16 | import org.junit.Test;
|
15 | 17 | import org.junit.runner.RunWith;
|
|
21 | 23 | import java.util.Arrays;
|
22 | 24 | import java.util.Collections;
|
23 | 25 |
|
| 26 | +import static org.mockito.ArgumentMatchers.any; |
24 | 27 | import static org.mockito.ArgumentMatchers.anyInt;
|
25 | 28 | import static org.mockito.ArgumentMatchers.eq;
|
26 | 29 | import static org.mockito.Mockito.mock;
|
| 30 | +import static org.mockito.Mockito.times; |
27 | 31 | import static org.mockito.Mockito.verify;
|
28 | 32 | import static org.mockito.Mockito.verifyZeroInteractions;
|
29 | 33 | import static org.mockito.Mockito.when;
|
30 | 34 | import static org.mockito.Mockito.withSettings;
|
31 | 35 |
|
32 | 36 | @SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
|
33 | 37 | @RunWith(PowerMockRunner.class)
|
34 |
| -@PrepareForTest({Jenkins.class, Queue.class}) |
| 38 | +@PrepareForTest({Jenkins.class, Queue.class, WorkflowJob.class, WorkflowRun.class}) |
35 | 39 | public class EC2FleetAutoResubmitComputerLauncherTest {
|
36 | 40 |
|
37 | 41 | @Mock
|
@@ -84,6 +88,12 @@ public class EC2FleetAutoResubmitComputerLauncherTest {
|
84 | 88 | @Mock
|
85 | 89 | private EC2FleetCloud cloud;
|
86 | 90 |
|
| 91 | + @Mock |
| 92 | + private WorkflowJob workflowJob; |
| 93 | + |
| 94 | + @Mock |
| 95 | + private WorkflowRun workflowRun; |
| 96 | + |
87 | 97 | @Before
|
88 | 98 | public void before() {
|
89 | 99 | executable1 = mock(Actionable.class, withSettings().extraInterfaces(Queue.Executable.class));
|
@@ -176,4 +186,16 @@ public void taskCompleted_should_resubmit_task_with_actions() {
|
176 | 186 | verifyZeroInteractions(queue);
|
177 | 187 | }
|
178 | 188 |
|
| 189 | + @Test |
| 190 | + public void taskCompleted_should_resubmit_task_with_failed_build_actions() { |
| 191 | + when(subTask1.getOwnerTask()).thenReturn(workflowJob); |
| 192 | + when(workflowJob.getLastFailedBuild()).thenReturn(workflowRun); |
| 193 | + when(workflowRun.getActions(any())).thenReturn((Collections.singletonList(action1))); |
| 194 | + when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); |
| 195 | + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) |
| 196 | + .afterDisconnect(computer, taskListener); |
| 197 | + verify(queue).schedule2(eq(workflowJob), anyInt(), eq(Arrays.asList(action1))); |
| 198 | + verify(workflowRun, times(1)).getActions(any()); |
| 199 | + } |
| 200 | + |
179 | 201 | }
|
0 commit comments