-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from wenduwan/eni_retry
amazon-ecs plugin: retry transient ECS task launch failures
- Loading branch information
Showing
2 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/test/java/com/cloudbees/jenkins/plugins/amazonecs/ECSLauncherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.cloudbees.jenkins.plugins.amazonecs; | ||
|
||
|
||
import com.amazonaws.services.ecs.model.Task; | ||
import com.amazonaws.waiters.WaiterUnrecoverableException; | ||
import hudson.model.TaskListener; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
|
||
public class ECSLauncherTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void generic_ecs_exception_is_not_retried() throws Exception { | ||
|
||
ECSService ecsService = mock(ECSService.class); | ||
ECSCloud cloud = mock(ECSCloud.class); | ||
ECSComputer computer = mock(ECSComputer.class); | ||
TaskListener listener = mock(TaskListener.class); | ||
ByteArrayOutputStream bo = new ByteArrayOutputStream(); | ||
Mockito.when(computer.getNode()).thenReturn(mock(ECSSlave.class)); | ||
Mockito.when(cloud.getEcsService()).thenReturn(ecsService); | ||
Mockito.when(listener.getLogger()).thenReturn(new PrintStream(bo)); | ||
|
||
ECSLauncher launcher = Mockito.spy(new ECSLauncher(cloud, "tunnel", "")); | ||
|
||
doThrow(new WaiterUnrecoverableException("Generic ecs exception")).when(launcher).launchECSTask(any(ECSComputer.class), any(TaskListener.class), anyLong()); | ||
|
||
assertThrows("Generic ECS exception", WaiterUnrecoverableException.class, () -> { | ||
launcher.launch(computer, listener); | ||
}); | ||
|
||
verify(launcher, times(1)).launchECSTask(any(ECSComputer.class), any(TaskListener.class), anyLong()); | ||
} | ||
|
||
@Test | ||
public void eni_timeout_exception_is_retried() throws Exception { | ||
|
||
ECSService ecsService = mock(ECSService.class); | ||
ECSCloud cloud = mock(ECSCloud.class); | ||
ECSComputer computer = mock(ECSComputer.class); | ||
TaskListener listener = mock(TaskListener.class); | ||
ByteArrayOutputStream bo = new ByteArrayOutputStream(); | ||
Mockito.when(computer.getNode()).thenReturn(mock(ECSSlave.class)); | ||
Mockito.when(cloud.getEcsService()).thenReturn(ecsService); | ||
Mockito.when(listener.getLogger()).thenReturn(new PrintStream(bo)); | ||
|
||
ECSLauncher launcher = Mockito.spy(new ECSLauncher(cloud, "tunnel", "")); | ||
|
||
doThrow(ECSLauncher.RetryableLaunchFailure.class).doReturn(mock(Task.class)).when(launcher).launchECSTask(any(ECSComputer.class), any(TaskListener.class), anyLong()); | ||
doNothing().when(launcher).waitForAgent(any(ECSSlave.class), any(TaskListener.class), anyLong()); | ||
|
||
launcher.launch(computer, listener); | ||
|
||
verify(launcher, times(2)).launchECSTask(any(ECSComputer.class), any(TaskListener.class), anyLong()); | ||
} | ||
} |