Skip to content

Commit

Permalink
control-service: if a test is in a bad state if fails straight away (#…
Browse files Browse the repository at this point in the history
…2098)

# Why
If a test goes into a final state that doesn't match the state we are
looking for. we can spend a couple of minutes waiting and checking does
it go to the state we want.

examples of this. 
We want a job to end with platform error. 
The job reports user error. 
we will spend 5 minutes checking is it user error. 

Total waste of time. 

# What
I have added in a fail fast clause that says if the job is not in a
running state and not in the final state we want then fail fast.



# How was this tested
Locally

---------

Signed-off-by: murphp15 <[email protected]>
Co-authored-by: github-actions <>
  • Loading branch information
murphp15 authored May 29, 2023
1 parent 9071910 commit e326757
Showing 1 changed file with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

Expand All @@ -23,13 +24,16 @@
import com.vmware.taurus.service.model.ExecutionType;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.assertj.core.util.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;

import static com.vmware.taurus.controlplane.model.data.DataJobExecution.StatusEnum.RUNNING;
import static com.vmware.taurus.controlplane.model.data.DataJobExecution.StatusEnum.SUBMITTED;
import static com.vmware.taurus.datajobs.it.common.BaseIT.HEADER_X_OP_ID;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -161,43 +165,43 @@ public static void testDataJobExecutionRead(
String username,
MockMvc mockMvc) {

com.vmware.taurus.controlplane.model.data.DataJobExecution[] dataJobExecution =
new com.vmware.taurus.controlplane.model.data.DataJobExecution[1];

await()
.atMost(5, TimeUnit.MINUTES)
.with()
.pollInterval(15, TimeUnit.SECONDS)
.until(
() -> {
String dataJobExecutionReadUrl =
String.format(
"/data-jobs/for-team/%s/jobs/%s/executions/%s",
teamName, jobName, executionId);
MvcResult dataJobExecutionResult =
mockMvc
.perform(
get(dataJobExecutionReadUrl)
.with(user(username))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();

dataJobExecution[0] =
objectMapper.readValue(
dataJobExecutionResult.getResponse().getContentAsString(),
com.vmware.taurus.controlplane.model.data.DataJobExecution.class);
if (dataJobExecution[0] == null) {
log.info("No response from server");
} else {
log.info("Response from server " + dataJobExecution[0].getStatus());
}
return dataJobExecution[0] != null
&& executionStatus.equals(dataJobExecution[0].getStatus());
});

assertDataJobExecutionValid(
executionId, executionStatus, opId, dataJobExecution[0], jobName, username);
Callable<com.vmware.taurus.controlplane.model.data.DataJobExecution> dataJobExecutionCallable =
() -> {
String dataJobExecutionReadUrl =
String.format(
"/data-jobs/for-team/%s/jobs/%s/executions/%s", teamName, jobName, executionId);
MvcResult dataJobExecutionResult =
mockMvc
.perform(
get(dataJobExecutionReadUrl)
.with(user(username))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();

return objectMapper.readValue(
dataJobExecutionResult.getResponse().getContentAsString(),
com.vmware.taurus.controlplane.model.data.DataJobExecution.class);
};

var result =
await()
.atMost(5, TimeUnit.MINUTES)
.with()
.pollInterval(15, TimeUnit.SECONDS)
.failFast(
() -> {
com.vmware.taurus.controlplane.model.data.DataJobExecution status =
dataJobExecutionCallable.call();
return status != null
&& !Lists.newArrayList(RUNNING, SUBMITTED).contains(status.getStatus())
&& !executionStatus.equals(status.getStatus());
})
.until(
dataJobExecutionCallable,
statusEnum -> statusEnum != null && executionStatus.equals(statusEnum.getStatus()));

assertDataJobExecutionValid(executionId, executionStatus, opId, result, jobName, username);
}

public static void testDataJobExecutionList(
Expand Down

0 comments on commit e326757

Please sign in to comment.