Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #335 #388

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void afterDisconnect(final SlaveComputer computer, final TaskListener lis

final List<Action> actions = new ArrayList<>();
if (task instanceof WorkflowJob) {
final WorkflowRun failedBuild = ((WorkflowJob) task).getLastBuild();
final WorkflowRun failedBuild = ((WorkflowJob) task).getLastFailedBuild();
actions.addAll(failedBuild.getActions(ParametersAction.class));
}
if (executable instanceof Actionable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import hudson.model.queue.SubTask;
import hudson.slaves.ComputerLauncher;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -21,17 +23,19 @@
import java.util.Arrays;
import java.util.Collections;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
@RunWith(PowerMockRunner.class)
@PrepareForTest({Jenkins.class, Queue.class})
@PrepareForTest({Jenkins.class, Queue.class, WorkflowJob.class, WorkflowRun.class})
public class EC2FleetAutoResubmitComputerLauncherTest {

@Mock
Expand Down Expand Up @@ -84,6 +88,12 @@ public class EC2FleetAutoResubmitComputerLauncherTest {
@Mock
private EC2FleetCloud cloud;

@Mock
private WorkflowJob workflowJob;

@Mock
private WorkflowRun workflowRun;

@Before
public void before() {
executable1 = mock(Actionable.class, withSettings().extraInterfaces(Queue.Executable.class));
Expand Down Expand Up @@ -176,4 +186,16 @@ public void taskCompleted_should_resubmit_task_with_actions() {
verifyZeroInteractions(queue);
}

@Test
public void taskCompleted_should_resubmit_task_with_failed_build_actions() {
when(subTask1.getOwnerTask()).thenReturn(workflowJob);
when(workflowJob.getLastFailedBuild()).thenReturn(workflowRun);
when(workflowRun.getActions(any())).thenReturn((Collections.singletonList(action1)));
when(computer.getExecutors()).thenReturn(Arrays.asList(executor1));
new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher)
.afterDisconnect(computer, taskListener);
verify(queue).schedule2(eq(workflowJob), anyInt(), eq(Arrays.asList(action1)));
verify(workflowRun, times(1)).getActions(any());
}

}