Skip to content

Commit

Permalink
fix(engine): ensure all parents dependencies are final
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Bétrancourt <[email protected]>
  • Loading branch information
rclsilver committed Apr 27, 2023
1 parent 865467f commit 9290d3c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
18 changes: 17 additions & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ func availableSteps(modifiedSteps map[string]bool, res *resolution.Resolution, e
// - dependency state is ANY, and depStep is in a final state
// - depStep is a child of a Foreach loop step in TO_RETRY state, and child is not running

if res.Steps[depStep].IsFinal() && depStates[0] == step.StateAny {
if res.Steps[depStep].IsFinal() && depStates[0] == step.StateAny && parentDepsAreFinal(res, res.Steps[depStep]) {
// if dependency doesn't require a specific state, and depStep is in a final state
// then dependency is matching
continue
Expand Down Expand Up @@ -992,6 +992,22 @@ func availableSteps(modifiedSteps map[string]bool, res *resolution.Resolution, e
return available
}

func parentDepsAreFinal(res *resolution.Resolution, stp *step.Step) bool {
for _, dep := range stp.Dependencies {
depStep, _ := step.DependencyParts(dep)

if !res.Steps[depStep].IsFinal() {
return false
}

if !parentDepsAreFinal(res, res.Steps[depStep]) {
return false
}
}

return true
}

func nextRetry(res *resolution.Resolution) *time.Time {
stepsToRetry := []*step.Step{}
for _, s := range res.Steps {
Expand Down
15 changes: 15 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,21 @@ func TestAnyDependency(t *testing.T) {
assert.Equal(t, step.StateDone, finalOKState)
}

func TestIndirectDependencies(t *testing.T) {
res, err := createResolution("indirectDependencies.yaml", map[string]interface{}{}, nil)
assert.NotNil(t, res)
assert.Nil(t, err)

res, err = runResolution(res)
assert.NotNil(t, res)
assert.Nil(t, err)

assert.Equal(t, step.StateDone, res.Steps["stepOne"].State)
assert.Equal(t, step.StateFatalError, res.Steps["stepTwo"].State)
assert.Equal(t, step.StatePrune, res.Steps["stepThree"].State)
assert.Equal(t, step.StateTODO, res.Steps["stepFour"].State)
}

func TestMetadata(t *testing.T) {
res, err := createResolution("metadata.yaml", map[string]interface{}{}, nil)
assert.NotNil(t, res)
Expand Down
50 changes: 50 additions & 0 deletions engine/templates_tests/indirectDependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: indirectDependencies
description: Indirect dependencies must be verified
title_format: "[test] indirect dependencies test"

steps:
stepOne:
action:
type: echo
configuration:
output: {}
conditions:
- type: check
if:
- value: '1'
operator: EQ
expected: '1'
then:
stepThree: PRUNE

stepTwo:
dependencies:
- stepOne
action:
type: echo
configuration:
output: {}
conditions:
- type: check
if:
- value: '1'
operator: EQ
expected: '1'
then:
this: FATAL_ERROR

stepThree:
dependencies:
- stepTwo
action:
type: echo
configuration:
output: {}

stepFour:
dependencies:
- stepThree:ANY
action:
type: echo
configuration:
output: {}

0 comments on commit 9290d3c

Please sign in to comment.