Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine): ensure all parents dependencies are final #412

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,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 @@ -982,6 +982,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: {}