From 9a514c2f136aa42ebe9212c4ab1a526cfbe933c3 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 27 Jan 2026 10:18:40 +0100 Subject: pkg/aflow: add explicit DoWhile.MaxIterations Add DoWhile.MaxIterations and make it mandatory. I think it's useful to make workflow implementer to think explicitly about a reasonable cap on the number of iterations. --- pkg/aflow/loop_test.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'pkg/aflow/loop_test.go') diff --git a/pkg/aflow/loop_test.go b/pkg/aflow/loop_test.go index e68191c2b..782a470b1 100644 --- a/pkg/aflow/loop_test.go +++ b/pkg/aflow/loop_test.go @@ -47,7 +47,8 @@ func TestDoWhile(t *testing.T) { return testResults{Diff: "diff"}, nil }), ), - While: "TestError", + While: "TestError", + MaxIterations: 10, }, nil, ) @@ -63,7 +64,8 @@ func TestDoWhileErrors(t *testing.T) { }) (struct{}, error) { return struct{}{}, nil }), - While: "Condition", + While: "Condition", + MaxIterations: 10, }, )) @@ -76,6 +78,7 @@ func TestDoWhileErrors(t *testing.T) { }) (struct{}, error) { return struct{}{}, nil }), + MaxIterations: 10, }, )) @@ -85,6 +88,17 @@ func TestDoWhileErrors(t *testing.T) { } testRegistrationError[struct{}, struct{}](t, "flow test: action body: output Output2 is unused", + Pipeline( + &DoWhile{ + Do: NewFuncAction("body", func(ctx *Context, args struct{}) (output, error) { + return output{}, nil + }), + While: "Output1", + MaxIterations: 10, + }, + )) + testRegistrationError[struct{}, struct{}](t, + "flow test: action DoWhile: bad MaxIterations value 0, should be within [1, 1000]", Pipeline( &DoWhile{ Do: NewFuncAction("body", func(ctx *Context, args struct{}) (output, error) { @@ -94,3 +108,19 @@ func TestDoWhileErrors(t *testing.T) { }, )) } + +func TestDoWhileMaxIters(t *testing.T) { + type actionResults struct { + Error string + } + testFlow[struct{}, struct{}](t, nil, "DoWhile loop is going in cycles for 3 iterations", + &DoWhile{ + Do: NewFuncAction("nop", func(ctx *Context, args struct{}) (actionResults, error) { + return actionResults{"failed"}, nil + }), + While: "Error", + MaxIterations: 3, + }, + nil, + ) +} -- cgit mrf-deployment