Skip to content

Commit

Permalink
Merge pull request ManageIQ#285 from agrare/map_state_exceed_tolerate…
Browse files Browse the repository at this point in the history
…d_failure_threshold

Return ExceedToleratedFailureThreshold if ToleratedFailureCount/Percentage is present
  • Loading branch information
kbrock authored Oct 10, 2024
2 parents dfe547e + 944fd1e commit f886dc5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/floe/workflow/states/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ def step_nonblock!(context)
end

def parse_error(context)
each_item_processor(context).detect(&:failed?)&.output&.dig("Error")
# If ToleratedFailureCount or ToleratedFailurePercentage is present
# then use States.ExceedToleratedFailureThreshold otherwise
# take the error from the first failed state
if tolerated_failure_count || tolerated_failure_percentage
{"Error" => "States.ExceedToleratedFailureThreshold"}
else
each_item_processor(context).detect(&:failed?)&.output || {"Error" => "States.Error"}
end
end

def validate_state!(workflow)
Expand Down
40 changes: 40 additions & 0 deletions spec/workflow/states/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,46 @@
end
end

describe "#finish" do
before { state.start(ctx) }

context "with mixed success and failures" do
before do
ctx.state["ItemProcessorContext"][0]["State"] = {"Output" => {"Error" => "States.TaskFailed"}}
ctx.state["ItemProcessorContext"][2]["State"] = {"Output" => {"Error" => "States.TaskFailed"}}
end

it "sets the state error to error from the ItemProcessor" do
state.finish(ctx)

expect(ctx.failed?).to be_truthy
expect(ctx.output).to eq("Error" => "States.TaskFailed")
end

context "with ToleratedFailureCount" do
let(:tolerated_failure_count) { 1 }

it "sets the state error to States.ExceedToleratedFailureThreshold" do
state.finish(ctx)

expect(ctx.failed?).to be_truthy
expect(ctx.output).to eq("Error" => "States.ExceedToleratedFailureThreshold")
end
end

context "with ToleratedFailurePercentage" do
let(:tolerated_failure_percentage) { 20 }

it "sets the state error to States.ExceedToleratedFailureThreshold" do
state.finish(ctx)

expect(ctx.failed?).to be_truthy
expect(ctx.output).to eq("Error" => "States.ExceedToleratedFailureThreshold")
end
end
end
end

describe "#running?" do
before { state.start(ctx) }

Expand Down

0 comments on commit f886dc5

Please sign in to comment.