Make some test timeouts (await) configurable (#2525)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-07-02 12:45:26 +03:00
committed by GitHub
parent bdbc658ea9
commit 8c6d56f177
77 changed files with 188 additions and 211 deletions

View File

@@ -19,14 +19,11 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
@@ -42,7 +39,7 @@ import org.springframework.test.web.servlet.ResultActions;
/**
* Integration test for the {@link MgmtActionRestApi}.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Action Resource
*/
@@ -65,7 +62,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
* Handles the GET request of retrieving a specific action.
*/
@Test
void getAction() throws Exception {
void getAction() throws Exception {
getAction(false);
}
@@ -73,7 +70,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
* Handles the GET request of retrieving a specific action with external reference.
*/
@Test
void getActionExtRef() throws Exception {
void getActionExtRef() throws Exception {
getAction(true);
}
@@ -82,7 +79,6 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
*/
@Test
void filterActionsByStatus() throws Exception {
// prepare test
final DistributionSet dsA = testdataFactory.createDistributionSet("");
assignDistributionSet(dsA, Collections.singletonList(testdataFactory.createTarget("knownTargetId")));
@@ -217,8 +213,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).code(200)
.message("Update succeeded").status(Status.FINISHED));
// verify that one result is returned if the actions are filtered for
// status code 200
// verify that one result is returned if the actions are filtered for status code 200
final String rsqlStatusCode = "lastStatusCode==200";
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlStatusCode))
.andDo(MockMvcResultPrinter.print())
@@ -227,8 +222,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("size", equalTo(1)))
.andExpect(jsonPath("content[0].status", equalTo("finished")));
// verify no result is returned if we filter for a non-existing status
// code
// verify no result is returned if we filter for a non-existing status code
final String rsqlWrongStatusCode = "lastStatusCode==999";
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlWrongStatusCode))
.andDo(MockMvcResultPrinter.print())
@@ -298,8 +292,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
// rollout
final Target target1 = testdataFactory.createTarget("t1");
final Rollout rollout = testdataFactory.createRolloutByVariables("TestRollout", "TestDesc", 1,
"name==" + target1.getName(), ds, "50", "5");
final Rollout rollout = testdataFactory.createRolloutByVariables(
"TestRollout", "TestDesc", 1, "name==" + target1.getName(), ds, "50", "5");
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();
@@ -517,8 +511,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
}
private static String generateActionLink(final String targetId, final Long actionId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/" +
MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING +
"/" + targetId + "/" + MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
}
private static String generateTargetLink(final String targetId) {
@@ -526,8 +520,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
}
private static String generateDistributionSetLink(final Action action) {
return "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/"
+ action.getDistributionSet().getId();
return "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + action.getDistributionSet().getId();
}
private void verifyResultsByTargetPropertyFilter(final Target target, final DistributionSet ds, final String rsqlTargetFilter)
@@ -598,13 +591,12 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet();
// rollout
final Target target = testdataFactory.createTarget(knownTargetId);
final Rollout rollout = testdataFactory.createRolloutByVariables("TestRollout", "TestDesc", 1,
"name==" + target.getName(), ds, "50", "5");
final Rollout rollout = testdataFactory.createRolloutByVariables(
"TestRollout", "TestDesc", 1, "name==" + target.getName(), ds, "50", "5");
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();
final List<Action> actions = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE)
.getContent();
final List<Action> actions = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent();
assertThat(actions).hasSize(1);
final String externalRef = "externalRef#123";
if (withExternalRef) {
@@ -625,8 +617,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
return generateTargetWithTwoUpdatesWithOneOverrideWithMaintenanceWindow(knownTargetId, null, null, null);
}
private List<Action> generateTargetWithTwoUpdatesWithOneOverrideWithMaintenanceWindow(final String knownTargetId,
final String schedule, final String duration, final String timezone) {
private List<Action> generateTargetWithTwoUpdatesWithOneOverrideWithMaintenanceWindow(
final String knownTargetId, final String schedule, final String duration, final String timezone) {
final Target target = testdataFactory.createTarget(knownTargetId);
final Iterator<DistributionSet> sets = testdataFactory.createDistributionSets(2).iterator();
@@ -639,26 +631,22 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
.getAssignedEntity().stream().map(Action::getTarget).toList();
// 2nd update
// sleep 10ms to ensure that we can sort by reportedAt
Awaitility.await().atMost(Duration.ofMillis(100)).atLeast(5, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
await().until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
assignDistributionSet(two, updatedTargets);
} else {
final List<Target> updatedTargets = assignDistributionSetWithMaintenanceWindow(one.getId(),
target.getControllerId(), schedule, duration, timezone).getAssignedEntity().stream()
.map(Action::getTarget).toList();
final List<Target> updatedTargets =
assignDistributionSetWithMaintenanceWindow(one.getId(), target.getControllerId(), schedule, duration, timezone)
.getAssignedEntity().stream()
.map(Action::getTarget)
.toList();
// 2nd update
// sleep 10ms to ensure that we can sort by reportedAt
Awaitility.await().atMost(Duration.ofMillis(100)).atLeast(5, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
assignDistributionSetWithMaintenanceWindow(two.getId(), updatedTargets.get(0).getControllerId(), schedule,
duration, timezone);
await().until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
assignDistributionSetWithMaintenanceWindow(two.getId(), updatedTargets.get(0).getControllerId(), schedule, duration, timezone);
}
// two updates, one cancellation
final List<Action> actions = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE)
.getContent();
final List<Action> actions = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent();
assertThat(actions).hasSize(2);
return actions;

View File

@@ -46,7 +46,7 @@ import org.springframework.test.web.servlet.MvcResult;
/**
* Test for {@link MgmtDistributionSetTypeResource}.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Distribution Set Type Resource
*/

View File

@@ -34,8 +34,8 @@ import java.util.Optional;
import java.util.stream.Stream;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionFactory;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
@@ -74,7 +74,7 @@ import org.springframework.test.web.servlet.ResultMatcher;
/**
* Tests for covering the {@link MgmtRolloutResource}.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Rollout Resource
*/
@@ -95,7 +95,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Handles the GET request of retrieving a single rollout.
*/
@Test
void getRollout() throws Exception {
void getRollout() throws Exception {
enableMultiAssignments();
approvalStrategy.setApprovalNeeded(true);
try {
@@ -132,7 +132,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Handles the GET request of retrieving a all targets of a specific deploy group of a rollout.
*/
@Test
void getRolloutDeployGroupTargetsWithParameters() throws Exception {
void getRolloutDeployGroupTargetsWithParameters() throws Exception {
testdataFactory.createTargets(4, "rollout", "description");
final DistributionSet dsA = testdataFactory.createDistributionSet("");
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
@@ -152,7 +152,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Handles the POST request of approving a rollout.
*/
@Test
void approveRollout() throws Exception {
void approveRollout() throws Exception {
approvalStrategy.setApprovalNeeded(true);
try {
testdataFactory.createTargets(4, "rollout", "description");
@@ -190,7 +190,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Check if approvalDecidedBy and approvalRemark are present when rollout is approved
*/
@Test
void validateIfApprovalFieldsArePresentAfterApproval() throws Exception {
void validateIfApprovalFieldsArePresentAfterApproval() throws Exception {
approvalStrategy.setApprovalNeeded(true);
approvalStrategy.setApproveDecidedBy("testUser");
final int amountTargets = 2;
@@ -223,7 +223,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Retry rollout test scenario
*/
@Test
void retryRolloutTest() throws Exception {
void retryRolloutTest() throws Exception {
final DistributionSet dsA = testdataFactory.createDistributionSet("");
final List<Target> successTargets = testdataFactory.createTargets("retryRolloutTargetSuccess-", 6);
@@ -294,7 +294,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Retrying a running rollout should not be allowed.
*/
@Test
void retryNotFinishedRolloutShouldNotBeAllowed() throws Exception {
void retryNotFinishedRolloutShouldNotBeAllowed() throws Exception {
final DistributionSet dsA = testdataFactory.createDistributionSet("");
testdataFactory.createTargets("retryRolloutTarget-", 10);
postRollout("rolloutToBeRetried", 1, dsA.getId(), "id==retryRolloutTarget*", 10, Action.ActionType.FORCED);
@@ -314,7 +314,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
* Retrying a non-existing rollout should lead to NOT FOUND.
*/
@Test
void retryNonExistingRolloutShouldLeadToNotFound() throws Exception {
void retryNonExistingRolloutShouldLeadToNotFound() throws Exception {
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/retry", 6782623))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
@@ -1911,19 +1911,22 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
}
private void awaitRunningState(final Long rolloutId) {
Awaitility.await().atMost(Duration.ofMinutes(1)).pollInterval(Duration.ofMillis(100)).with()
.until(() -> SecurityContextSwitch
.runAsPrivileged(
() -> rolloutManagement.get(rolloutId).orElseThrow(NoSuchElementException::new))
.getStatus().equals(RolloutStatus.RUNNING));
awaitRollout().until(() -> SecurityContextSwitch
.runAsPrivileged(() -> rolloutManagement.get(rolloutId).orElseThrow(NoSuchElementException::new))
.getStatus().equals(RolloutStatus.RUNNING));
}
private void awaitActionStatus(final Long actionId, final Status status) {
Awaitility.await().atMost(Duration.ofMinutes(1)).pollInterval(Duration.ofMillis(100)).with()
.until(() -> SecurityContextSwitch
.runAsPrivileged(
() -> deploymentManagement.findAction(actionId).orElseThrow(NoSuchElementException::new))
.getStatus().equals(status));
awaitRollout().until(() -> SecurityContextSwitch
.runAsPrivileged(() -> deploymentManagement.findAction(actionId).orElseThrow(NoSuchElementException::new))
.getStatus().equals(status));
}
private static final Duration ROLLOUT_AT_LEAST = Duration.ofMillis(Integer.getInteger("hawkbit.it.rest.await.rolloutAtLeastMs", 50));
private static final Duration ROLLOUT_POLL_INTERVAL = Duration.ofMillis(Integer.getInteger("hawkbit.it.rest.await.rolloutPollIntervalMs", 100));
private static final Duration ROLLOUT_TIMEOUT = Duration.ofMillis(Integer.getInteger("hawkbit.it.rest.await.rolloutTimeoutMs", 60_000));
private ConditionFactory awaitRollout() {
return Awaitility.await().atLeast(ROLLOUT_AT_LEAST).pollInterval(ROLLOUT_POLL_INTERVAL).atMost(ROLLOUT_TIMEOUT);
}
private void assertStatusIs(final Rollout rollout, final RolloutStatus expected) {

View File

@@ -32,16 +32,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import com.jayway.jsonpath.JsonPath;
import org.apache.commons.io.IOUtils;
import org.awaitility.Awaitility;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
@@ -83,7 +80,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* Tests for {@link MgmtSoftwareModuleResource} {@link RestController}.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Software Module Resource
*/
@@ -249,10 +246,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.toString();
// ensures that we are not to fast so that last modified is not set correctly
Awaitility.await()
.atMost(Duration.ofMillis(100))
.pollInterval(10L, TimeUnit.MILLISECONDS)
.until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
await().until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON))
@@ -292,10 +286,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String body = new JSONObject().put("deleted", true).toString();
// ensures that we are not to fast so that last modified is not set correctly
Awaitility.await()
.atMost(Duration.ofMillis(100))
.pollInterval(10L, TimeUnit.MILLISECONDS)
.until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
await().until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON))
@@ -323,10 +314,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
entityFactory.softwareModule().create().type(osType).name("name1").version("version1"));
assertThat(sm.isLocked()).as("Created software module should not be locked").isFalse();
// ensures that we are not to fast so that last modified is not set correctly
Awaitility.await()
.atMost(Duration.ofMillis(100))
.pollInterval(10L, TimeUnit.MILLISECONDS)
.until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
await().until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
// lock
final String body = new JSONObject().put("locked", true).toString();
@@ -361,10 +349,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.as("Software module is locked")
.isTrue();
// ensures that we are not to fast so that last modified is not set correctly
Awaitility.await()
.atMost(Duration.ofMillis(100))
.pollInterval(10L, TimeUnit.MILLISECONDS)
.until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
await().until(() -> sm.getLastModifiedAt() > 0L && sm.getLastModifiedBy() != null);
// unlock
final String body = new JSONObject().put("locked", false).toString();

View File

@@ -41,7 +41,7 @@ import org.springframework.test.web.servlet.MvcResult;
/**
* Test for {@link MgmtSoftwareModuleTypeResource}.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Software Module Type Resource
*/

View File

@@ -55,7 +55,7 @@ import org.springframework.web.util.UriUtils;
/**
* Spring MVC Tests against the MgmtTargetResource.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Target Filter Query Resource
*/

View File

@@ -30,7 +30,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -40,14 +39,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import jakarta.validation.ConstraintViolationException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
import org.awaitility.Awaitility;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtActionConfirmationRequestBodyPut;
@@ -102,7 +99,7 @@ import org.springframework.test.web.servlet.ResultActions;
/**
* Spring MVC Tests against the MgmtTargetResource.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Target Resource
*/
@@ -2971,9 +2968,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.getAssignedEntity().stream().map(Action::getTarget).toList();
// 2nd update
// sleep 10ms to ensure that we can sort by reportedAt
Awaitility.await().atMost(Duration.ofMillis(100)).atLeast(5, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
await().until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
assignDistributionSet(two, updatedTargets);
} else {
final List<Target> updatedTargets = assignDistributionSetWithMaintenanceWindow(one.getId(),
@@ -2981,9 +2976,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
.map(Action::getTarget).toList();
// 2nd update
// sleep 10ms to ensure that we can sort by reportedAt
Awaitility.await().atMost(Duration.ofMillis(100)).atLeast(5, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
await().until(() -> updatedTargets.stream().allMatch(t -> t.getLastModifiedAt() > 0L));
assignDistributionSetWithMaintenanceWindow(two.getId(), updatedTargets.get(0).getControllerId(), schedule,
duration, timezone);
}

View File

@@ -50,7 +50,7 @@ import org.springframework.test.web.servlet.ResultActions;
/**
* Spring MVC Tests against the MgmtTargetTagResource.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Target Tag Resource
*/

View File

@@ -49,7 +49,7 @@ import org.springframework.test.web.servlet.ResultActions;
/**
* Spring MVC Tests against the MgmtTargetTypeResource.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Target Type Resource
*/

View File

@@ -32,7 +32,7 @@ import org.springframework.test.web.servlet.ResultMatcher;
/**
* Spring MVC Tests against the MgmtTenantManagementResource.
* <p/>
* <p/>
* Feature: Component Tests - Management API<br/>
* Story: Tenant Management Resource
*/