aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/aflow/loop_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-27 10:18:40 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-27 09:30:55 +0000
commit9a514c2f136aa42ebe9212c4ab1a526cfbe933c3 (patch)
treee795a6fb0e5248724e68cc259e7374443238e437 /pkg/aflow/loop_test.go
parent43e1df1d9b982f24e3ccba50cf8881eed86d8994 (diff)
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.
Diffstat (limited to 'pkg/aflow/loop_test.go')
-rw-r--r--pkg/aflow/loop_test.go34
1 files changed, 32 insertions, 2 deletions
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,
},
))
@@ -90,7 +93,34 @@ func TestDoWhileErrors(t *testing.T) {
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) {
+ return output{}, nil
+ }),
While: "Output1",
},
))
}
+
+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,
+ )
+}