From 0792c0a17d2f14ef131aece3af6e48966c83fc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Mon, 4 Apr 2022 12:31:27 +0200 Subject: [PATCH] Add missing limit arg. to workfow iterator handlers --- compose/automation/records_handler.go | 2 + system/automation/actionlog_handler.go | 2 + system/automation/roles_handler.go | 2 + system/automation/templates_handler.go | 2 + system/automation/users_handler.go | 2 + tests/workflows/0005_iterator_records_test.go | 39 +++++++++++++++++++ tests/workflows/0006_iterator_users_test.go | 36 +++++++++++++++++ tests/workflows/0007_iterator_roles_test.go | 36 +++++++++++++++++ .../workflows/0009_iterator_templates_test.go | 36 +++++++++++++++++ .../iterator_records_limit/data_model.yaml | 25 ++++++++++++ .../iterator_records_limit/workflow.yaml | 30 ++++++++++++++ .../iterator_roles_limit/data_model.yaml | 6 +++ .../iterator_roles_limit/workflow.yaml | 29 ++++++++++++++ .../iterator_templates_limit/data_model.yaml | 11 ++++++ .../iterator_templates_limit/workflow.yaml | 29 ++++++++++++++ .../iterator_users_limit/data_model.yaml | 6 +++ .../iterator_users_limit/workflow.yaml | 29 ++++++++++++++ 17 files changed, 322 insertions(+) create mode 100644 tests/workflows/testdata/iterator_records_limit/data_model.yaml create mode 100644 tests/workflows/testdata/iterator_records_limit/workflow.yaml create mode 100644 tests/workflows/testdata/iterator_roles_limit/data_model.yaml create mode 100644 tests/workflows/testdata/iterator_roles_limit/workflow.yaml create mode 100644 tests/workflows/testdata/iterator_templates_limit/data_model.yaml create mode 100644 tests/workflows/testdata/iterator_templates_limit/workflow.yaml create mode 100644 tests/workflows/testdata/iterator_users_limit/data_model.yaml create mode 100644 tests/workflows/testdata/iterator_users_limit/workflow.yaml diff --git a/compose/automation/records_handler.go b/compose/automation/records_handler.go index 5a59e648d..7e47dc8f3 100644 --- a/compose/automation/records_handler.go +++ b/compose/automation/records_handler.go @@ -209,6 +209,8 @@ func (h recordsHandler) each(ctx context.Context, args *recordsEachArgs) (out wf i.useIterLimit = true i.iterLimit = uint(args.Limit) + f.Limit = uint(args.Limit) + if args.Limit > uint64(wfexec.MaxIteratorBufferSize) { f.Limit = wfexec.MaxIteratorBufferSize } diff --git a/system/automation/actionlog_handler.go b/system/automation/actionlog_handler.go index b98c37519..22c1b3c84 100644 --- a/system/automation/actionlog_handler.go +++ b/system/automation/actionlog_handler.go @@ -84,6 +84,8 @@ func (h actionlogHandler) each(ctx context.Context, args *actionlogEachArgs) (ou i.useIterLimit = true i.iterLimit = uint(args.Limit) + f.Limit = uint(args.Limit) + if args.Limit > uint64(wfexec.MaxIteratorBufferSize) { f.Limit = wfexec.MaxIteratorBufferSize } diff --git a/system/automation/roles_handler.go b/system/automation/roles_handler.go index 6d7e21ca2..311cc5bf5 100644 --- a/system/automation/roles_handler.go +++ b/system/automation/roles_handler.go @@ -286,6 +286,8 @@ func (h rolesHandler) each(ctx context.Context, args *rolesEachArgs) (out wfexec i.useIterLimit = true i.iterLimit = uint(args.Limit) + f.Limit = uint(args.Limit) + if args.Limit > uint64(wfexec.MaxIteratorBufferSize) { f.Limit = wfexec.MaxIteratorBufferSize } diff --git a/system/automation/templates_handler.go b/system/automation/templates_handler.go index 144469476..def66adc1 100644 --- a/system/automation/templates_handler.go +++ b/system/automation/templates_handler.go @@ -137,6 +137,8 @@ func (h templatesHandler) each(ctx context.Context, args *templatesEachArgs) (ou i.useIterLimit = true i.iterLimit = uint(args.Limit) + f.Limit = uint(args.Limit) + if args.Limit > uint64(wfexec.MaxIteratorBufferSize) { f.Limit = wfexec.MaxIteratorBufferSize } diff --git a/system/automation/users_handler.go b/system/automation/users_handler.go index 522d04237..f26f696fc 100644 --- a/system/automation/users_handler.go +++ b/system/automation/users_handler.go @@ -238,6 +238,8 @@ func (h usersHandler) each(ctx context.Context, args *usersEachArgs) (out wfexec i.useIterLimit = true i.iterLimit = uint(args.Limit) + f.Limit = uint(args.Limit) + if args.Limit > uint64(wfexec.MaxIteratorBufferSize) { f.Limit = wfexec.MaxIteratorBufferSize } diff --git a/tests/workflows/0005_iterator_records_test.go b/tests/workflows/0005_iterator_records_test.go index 29796400b..ae72b6660 100644 --- a/tests/workflows/0005_iterator_records_test.go +++ b/tests/workflows/0005_iterator_records_test.go @@ -99,3 +99,42 @@ func Test0005_iterator_records_chunked(t *testing.T) { req.Equal(fmt.Sprintf("%d", ctr+1), rv.Value) } } + +func Test0005_iterator_records_limited(t *testing.T) { + var ( + ctx = bypassRBAC(context.Background()) + req = require.New(t) + ) + + req.NoError(defStore.TruncateComposeRecords(ctx, nil)) + req.NoError(defStore.TruncateComposeModules(ctx)) + req.NoError(defStore.TruncateComposeNamespaces(ctx)) + + loadScenarioWithName(ctx, t, "iterator_records_limit") + + var ( + _, trace = mustExecWorkflow(ctx, t, "testing", autTypes.WorkflowExecParams{}) + ) + + // 3x iterator, 2x continue, 1x terminator, 1x completed + req.Len(trace, 7) + + // there are 4 iterator calls; each on the *2 index + ctr := int64(-1) + for j := 0; j <= 1; j++ { + ix := j * 2 + ctr++ + + frame := trace[ix] + req.Equal(uint64(10), frame.StepID) + + i, err := expr.Integer{}.Cast(frame.Results.GetValue()["i"]) + req.NoError(err) + req.Equal(ctr, i.Get().(int64)) + + rec, err := automation.NewComposeRecord(frame.Results.GetValue()["r"]) + req.NoError(err) + rv := rec.GetValue().Values[0] + req.Equal(fmt.Sprintf("%d", ctr+1), rv.Value) + } +} diff --git a/tests/workflows/0006_iterator_users_test.go b/tests/workflows/0006_iterator_users_test.go index 0d7e36777..01c424e29 100644 --- a/tests/workflows/0006_iterator_users_test.go +++ b/tests/workflows/0006_iterator_users_test.go @@ -93,3 +93,39 @@ func Test0006_iterator_users_chunked(t *testing.T) { req.Equal(fmt.Sprintf("u%d", ctr+1), usr.GetValue().Handle) } } + +func Test0006_iterator_users_limited(t *testing.T) { + var ( + ctx = bypassRBAC(context.Background()) + req = require.New(t) + ) + + req.NoError(defStore.TruncateUsers(ctx)) + + loadScenarioWithName(ctx, t, "iterator_users_limit") + + var ( + _, trace = mustExecWorkflow(ctx, t, "testing", autTypes.WorkflowExecParams{}) + ) + + // 3x iterator, 2x continue, 1x terminator, 1x completed + req.Len(trace, 7) + + // there are 4 iterator calls; each on the *2 index + ctr := int64(-1) + for j := 0; j <= 1; j++ { + ix := j * 2 + ctr++ + + frame := trace[ix] + req.Equal(uint64(10), frame.StepID) + + i, err := expr.Integer{}.Cast(frame.Results.GetValue()["i"]) + req.NoError(err) + req.Equal(ctr, i.Get().(int64)) + + usr, err := automation.NewUser(frame.Results.GetValue()["u"]) + req.NoError(err) + req.Equal(fmt.Sprintf("u%d", ctr+1), usr.GetValue().Handle) + } +} diff --git a/tests/workflows/0007_iterator_roles_test.go b/tests/workflows/0007_iterator_roles_test.go index 74806f977..847320fb7 100644 --- a/tests/workflows/0007_iterator_roles_test.go +++ b/tests/workflows/0007_iterator_roles_test.go @@ -93,3 +93,39 @@ func Test0008_iterator_roles_chunked(t *testing.T) { req.Equal(fmt.Sprintf("r%d", ctr+1), usr.GetValue().Handle) } } + +func Test0008_iterator_roles_limited(t *testing.T) { + var ( + ctx = bypassRBAC(context.Background()) + req = require.New(t) + ) + + req.NoError(defStore.TruncateRoles(ctx)) + + loadScenarioWithName(ctx, t, "iterator_roles_limit") + + var ( + _, trace = mustExecWorkflow(ctx, t, "testing", autTypes.WorkflowExecParams{}) + ) + + // 3x iterator, 2x continue, 1x terminator, 1x completed + req.Len(trace, 7) + + // there are 4 iterator calls; each on the *2 index + ctr := int64(-1) + for j := 0; j <= 1; j++ { + ix := j * 2 + ctr++ + + frame := trace[ix] + req.Equal(uint64(10), frame.StepID) + + i, err := expr.Integer{}.Cast(frame.Results.GetValue()["i"]) + req.NoError(err) + req.Equal(ctr, i.Get().(int64)) + + usr, err := automation.NewRole(frame.Results.GetValue()["r"]) + req.NoError(err) + req.Equal(fmt.Sprintf("r%d", ctr+1), usr.GetValue().Handle) + } +} diff --git a/tests/workflows/0009_iterator_templates_test.go b/tests/workflows/0009_iterator_templates_test.go index ed0a1e34b..e265692ca 100644 --- a/tests/workflows/0009_iterator_templates_test.go +++ b/tests/workflows/0009_iterator_templates_test.go @@ -93,3 +93,39 @@ func Test0009_iterator_templates_chunked(t *testing.T) { req.Equal(fmt.Sprintf("t%d", ctr+1), tpl.GetValue().Handle) } } + +func Test0009_iterator_templates_limited(t *testing.T) { + var ( + ctx = bypassRBAC(context.Background()) + req = require.New(t) + ) + + req.NoError(defStore.TruncateTemplates(ctx)) + + loadScenarioWithName(ctx, t, "iterator_templates_limit") + + var ( + _, trace = mustExecWorkflow(ctx, t, "testing", autTypes.WorkflowExecParams{}) + ) + + // 3x iterator, 2x continue, 1x terminator, 1x completed + req.Len(trace, 7) + + // there are 4 iterator calls; each on the *2 index + ctr := int64(-1) + for j := 0; j <= 1; j++ { + ix := j * 2 + ctr++ + + frame := trace[ix] + req.Equal(uint64(10), frame.StepID) + + i, err := expr.Integer{}.Cast(frame.Results.GetValue()["i"]) + req.NoError(err) + req.Equal(ctr, i.Get().(int64)) + + tpl, err := automation.NewTemplate(frame.Results.GetValue()["tpl"]) + req.NoError(err) + req.Equal(fmt.Sprintf("t%d", ctr+1), tpl.GetValue().Handle) + } +} diff --git a/tests/workflows/testdata/iterator_records_limit/data_model.yaml b/tests/workflows/testdata/iterator_records_limit/data_model.yaml new file mode 100644 index 000000000..013f3e77c --- /dev/null +++ b/tests/workflows/testdata/iterator_records_limit/data_model.yaml @@ -0,0 +1,25 @@ +namespaces: + ns1: + name: ns1 name + +modules: + mod1: + name: mod1 name + fields: + f1: + label: f1 label + kind: String + required: false + +records: + mod1: + - values: + f1: 1 + - values: + f1: 2 + - values: + f1: 3 + - values: + f1: 4 + - values: + f1: 5 diff --git a/tests/workflows/testdata/iterator_records_limit/workflow.yaml b/tests/workflows/testdata/iterator_records_limit/workflow.yaml new file mode 100644 index 000000000..3ee978cfd --- /dev/null +++ b/tests/workflows/testdata/iterator_records_limit/workflow.yaml @@ -0,0 +1,30 @@ +workflows: + testing: + enabled: true + trace: true + triggers: + - enabled: true + stepID: 10 + + steps: + - stepID: 10 + kind: iterator + ref: composeRecordsEach + arguments: + - { "target": "module", "value": "mod1", "type": "Handle" } + - { "target": "namespace", "value": "ns1", "type": "Handle" } + - { "target": "limit", "value": "2", "type": "UnsignedInteger" } + results: + - { "target": "r", "expr": "record" } + - { "target": "i", "expr": "index" } + - { "target": "t", "expr": "total" } + + - stepID: 11 + kind: continue + + - stepID: 12 + kind: termination + + paths: + - { parentID: 10, childID: 11 } + - { parentID: 10, childID: 12 } diff --git a/tests/workflows/testdata/iterator_roles_limit/data_model.yaml b/tests/workflows/testdata/iterator_roles_limit/data_model.yaml new file mode 100644 index 000000000..17a84abd1 --- /dev/null +++ b/tests/workflows/testdata/iterator_roles_limit/data_model.yaml @@ -0,0 +1,6 @@ +roles: + r1: r1 name + r2: r2 name + r3: r3 name + r4: r4 name + r5: r5 name diff --git a/tests/workflows/testdata/iterator_roles_limit/workflow.yaml b/tests/workflows/testdata/iterator_roles_limit/workflow.yaml new file mode 100644 index 000000000..1f9204aa9 --- /dev/null +++ b/tests/workflows/testdata/iterator_roles_limit/workflow.yaml @@ -0,0 +1,29 @@ +workflows: + testing: + enabled: true + trace: true + triggers: + - enabled: true + stepID: 10 + + steps: + - stepID: 10 + kind: iterator + ref: rolesEach + arguments: + - { "target": "incTotal", "value": "false", "type": "Boolean" } + - { "target": "limit", "value": "2", "type": "UnsignedInteger" } + results: + - { "target": "r", "expr": "role" } + - { "target": "i", "expr": "index" } + - { "target": "t", "expr": "total" } + + - stepID: 11 + kind: continue + + - stepID: 12 + kind: termination + + paths: + - { parentID: 10, childID: 11 } + - { parentID: 10, childID: 12 } diff --git a/tests/workflows/testdata/iterator_templates_limit/data_model.yaml b/tests/workflows/testdata/iterator_templates_limit/data_model.yaml new file mode 100644 index 000000000..3ad311d22 --- /dev/null +++ b/tests/workflows/testdata/iterator_templates_limit/data_model.yaml @@ -0,0 +1,11 @@ +templates: + t1: + type: text/html + t2: + type: text/html + t3: + type: text/html + t4: + type: text/html + t5: + type: text/html diff --git a/tests/workflows/testdata/iterator_templates_limit/workflow.yaml b/tests/workflows/testdata/iterator_templates_limit/workflow.yaml new file mode 100644 index 000000000..b0d4f721e --- /dev/null +++ b/tests/workflows/testdata/iterator_templates_limit/workflow.yaml @@ -0,0 +1,29 @@ +workflows: + testing: + enabled: true + trace: true + triggers: + - enabled: true + stepID: 10 + + steps: + - stepID: 10 + kind: iterator + ref: templatesEach + arguments: + - { "target": "incTotal", "value": "false", "type": "Boolean" } + - { "target": "limit", "value": "2", "type": "UnsignedInteger" } + results: + - { "target": "tpl", "expr": "template" } + - { "target": "i", "expr": "index" } + - { "target": "t", "expr": "total" } + + - stepID: 11 + kind: continue + + - stepID: 12 + kind: termination + + paths: + - { parentID: 10, childID: 11 } + - { parentID: 10, childID: 12 } diff --git a/tests/workflows/testdata/iterator_users_limit/data_model.yaml b/tests/workflows/testdata/iterator_users_limit/data_model.yaml new file mode 100644 index 000000000..7ccf85402 --- /dev/null +++ b/tests/workflows/testdata/iterator_users_limit/data_model.yaml @@ -0,0 +1,6 @@ +users: + u1: u1@example.tld + u2: u2@example.tld + u3: u3@example.tld + u4: u4@example.tld + u5: u5@example.tld diff --git a/tests/workflows/testdata/iterator_users_limit/workflow.yaml b/tests/workflows/testdata/iterator_users_limit/workflow.yaml new file mode 100644 index 000000000..2340182b9 --- /dev/null +++ b/tests/workflows/testdata/iterator_users_limit/workflow.yaml @@ -0,0 +1,29 @@ +workflows: + testing: + enabled: true + trace: true + triggers: + - enabled: true + stepID: 10 + + steps: + - stepID: 10 + kind: iterator + ref: usersEach + arguments: + - { "target": "incTotal", "value": "false", "type": "Boolean" } + - { "target": "limit", "value": "2", "type": "UnsignedInteger" } + results: + - { "target": "u", "expr": "user" } + - { "target": "i", "expr": "index" } + - { "target": "t", "expr": "total" } + + - stepID: 11 + kind: continue + + - stepID: 12 + kind: termination + + paths: + - { parentID: 10, childID: 11 } + - { parentID: 10, childID: 12 }