Fix dynamic rollouts when there are finished actions from previous rollouts (#2434)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-06-06 16:13:21 +03:00
committed by GitHub
parent d166dd6224
commit 0e0b5ed6ff
6 changed files with 151 additions and 209 deletions

View File

@@ -147,9 +147,9 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void findByTargetFilterQueryAndNotInRolloutGroupsAndCompatibleAndUpdatablePermissionsCheck() {
void findByTargetFilterQueryAndNotInRolloutAndCompatibleAndUpdatablePermissionsCheck() {
assertPermissions(
() -> targetManagement.findByTargetFilterQueryAndNotInRolloutGroupsAndCompatibleAndUpdatable(PAGE, List.of(1L),
() -> targetManagement.findByTargetFilterQueryAndNotInRolloutAndCompatibleAndUpdatable(PAGE, List.of(1L),
"controllerId==id",
entityFactory.distributionSetType().create().build()), List.of(SpPermission.READ_TARGET, SpPermission.READ_ROLLOUT));
}

View File

@@ -789,8 +789,6 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
.isThrownBy(() -> targetManagement.createMetadata(target3ControllerId, metaData3));
}
@Test
@Description("Queries and loads the metadata related to a given target.")
void getMetadata() {
@@ -1114,8 +1112,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
void matchesFilterTargetNotExists() {
final DistributionSet ds = testdataFactory.createDistributionSet();
assertThat(targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable("notExisting", ds.getId(),
"name==*")).isFalse();
assertThat(targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(
"notExisting", ds.getId(),"name==*")).isFalse();
}
/**
@@ -1123,43 +1121,53 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
*/
@Test
@Description("Target matches filter no active action with ge weight.")
void findByNotInGEGroupAndNotInActiveActionGEWeightOrInRolloutAndTargetFilterQueryAndCompatibleAndUpdatable() {
void findByTargetFilterQueryAndNoOverridingActionsAndNotInRolloutAndCompatibleAndUpdatable() {
final String targetPrefix = "dyn_action_filter_";
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
final List<Target> targets = testdataFactory.createTargets(targetPrefix, 9);
final List<Target> targets = testdataFactory.createTargets(targetPrefix, 10);
final Rollout rolloutOlder = testdataFactory.createRollout();
final Rollout rollout = testdataFactory.createRollout();
final Rollout rolloutNewer = testdataFactory.createRollout();
int target = 0;
final List<Integer> expected = new ArrayList<>();
// old ro with less weight - match
createAction(targets.get(0), rolloutOlder, 0, Status.RUNNING, distributionSet);
// old ro with less weight - match
createAction(targets.get(1), rolloutOlder, 5, Status.SCHEDULED, distributionSet);
expected.add(target);
createAction(targets.get(target++), rolloutOlder, 0, Status.RUNNING, distributionSet);
// old ro with equal weight - match
createAction(targets.get(2), rolloutOlder, 10, Status.RUNNING, distributionSet);
// old ro with BIGGER weight - doesn't match
createAction(targets.get(3), rolloutOlder, 20, Status.WAIT_FOR_CONFIRMATION, distributionSet);
expected.add(target);
createAction(targets.get(target++), rolloutOlder, 10, Status.RUNNING, distributionSet);
// old ro with bigger weight, scheduled - doesn't match
createAction(targets.get(target++), rolloutOlder, 11, Status.SCHEDULED, distributionSet);
// old ro with bigger weight, running - doesn't match
createAction(targets.get(target++), rolloutOlder, 11, Status.RUNNING, distributionSet);
// old ro with bigger weight, running match
expected.add(target);
createAction(targets.get(target++), rolloutOlder, 11, Status.FINISHED, distributionSet);
// same ro - doesn't match
createAction(targets.get(4), rollout, 10, Status.RUNNING, distributionSet);
createAction(targets.get(target++), rollout, 10, Status.RUNNING, distributionSet);
// new ro with less weight - match
createAction(targets.get(5), rolloutNewer, 0, Status.RUNNING, distributionSet);
expected.add(target);
createAction(targets.get(target++), rolloutNewer, 0, Status.RUNNING, distributionSet);
// new ro with less weight - match
createAction(targets.get(6), rolloutNewer, 5, Status.WARNING, distributionSet);
expected.add(target);
createAction(targets.get(target++), rolloutNewer, 5, Status.WARNING, distributionSet);
// NEW ro with EQUAL weight - doesn't match
createAction(targets.get(7), rolloutNewer, 10, Status.RUNNING, distributionSet);
createAction(targets.get(target++), rolloutNewer, 10, Status.RUNNING, distributionSet);
// new ro with BIGGER weight - doesn't match
createAction(targets.get(8), rolloutNewer, 20, Status.DOWNLOADED, distributionSet);
createAction(targets.get(target), rolloutNewer, 20, Status.DOWNLOADED, distributionSet);
final Slice<Target> matching = targetManagement.findByNotInGEGroupAndNotInActiveActionGEWeightOrInRolloutAndTargetFilterQueryAndCompatibleAndUpdatable(
PAGE, rollout.getId(), 10, Long.MAX_VALUE, "controllerid==dyn_action_filter_*", distributionSet.getType());
final Slice<Target> matching =
targetManagement.findByTargetFilterQueryAndNoOverridingActionsAndNotInRolloutAndCompatibleAndUpdatable(
PAGE, rollout.getId(), 10, Long.MAX_VALUE, "controllerid==dyn_action_filter_*", distributionSet.getType());
assertThat(matching.getNumberOfElements()).isEqualTo(5);
assertThat(matching.getNumberOfElements()).isEqualTo(expected.size());
assertThat(matching.stream()
.map(Target::getControllerId)
.map(s -> s.substring(targetPrefix.length()))
.map(Integer::parseInt)
.sorted()
.toList()).isEqualTo(List.of(0, 1, 2, 5, 6));
.toList()).isEqualTo(expected);
}
@Test
@@ -1435,6 +1443,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
action.setWeight(weight);
}
action.setStatus(status);
action.setActive(status != Status.FINISHED && status != Status.ERROR && status != Status.CANCELED);
action.setDistributionSet(distributionSet);
actionRepository.save(action);
}