Skip to content

Commit

Permalink
Merge pull request ManageIQ#284 from agrare/map_state_add_tolerated_f…
Browse files Browse the repository at this point in the history
…ailure

Handle either tolerated_failure_count or tolerated_failure_percentage
  • Loading branch information
Fryguy authored Oct 9, 2024
2 parents e71822d + 369d341 commit dfe547e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/floe/workflow/states/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,18 @@ def success?(context)
total = contexts.count

return true if num_failed.zero? || total.zero?
return true if tolerated_failure_percentage && tolerated_failure_percentage == 100
return false if tolerated_failure_count.nil? && tolerated_failure_percentage.nil?

# Some have failed, check the tolerated_failure thresholds to see if
# we should fail the whole state.
return true if tolerated_failure_count && num_failed < tolerated_failure_count
return true if tolerated_failure_percentage && (100 * num_failed / total.to_f) < tolerated_failure_percentage

false
#
# If either ToleratedFailureCount or ToleratedFailurePercentage are breached
# then the whole state is considered failed.
count_tolerated = tolerated_failure_count.nil? || num_failed < tolerated_failure_count
pct_tolerated = tolerated_failure_percentage.nil? || tolerated_failure_percentage == 100 ||
((100 * num_failed / total.to_f) < tolerated_failure_percentage)

count_tolerated && pct_tolerated
end

private
Expand Down
38 changes: 38 additions & 0 deletions spec/workflow/states/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,44 @@
end
end
end

context "with both ToleratedFailureCount and ToleratedFailurePercentage" do
context "with ToleratedFailureCount being lower than the failed percentge" do
let(:tolerated_failure_percentage) { 50 }
let(:tolerated_failure_count) { 1 }

it "returns false" do
expect(state.success?(ctx)).to be_falsey
end
end

context "with ToleratedFailurePercentage being lower than the failed count" do
let(:tolerated_failure_percentage) { 10 }
let(:tolerated_failure_count) { 3 }

it "returns false" do
expect(state.success?(ctx)).to be_falsey
end
end

context "with neither being high enough for success" do
let(:tolerated_failure_percentage) { 10 }
let(:tolerated_failure_count) { 1 }

it "returns false" do
expect(state.success?(ctx)).to be_falsey
end
end

context "with both being high enough for success" do
let(:tolerated_failure_percentage) { 50 }
let(:tolerated_failure_count) { 3 }

it "returns true" do
expect(state.success?(ctx)).to be_truthy
end
end
end
end
end
end

0 comments on commit dfe547e

Please sign in to comment.