3
0

Add missing limit arg. to workfow iterator handlers

This commit is contained in:
Tomaž Jerman
2022-04-04 12:31:27 +02:00
parent 41667a7dae
commit 0792c0a17d
17 changed files with 322 additions and 0 deletions
+2
View File
@@ -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
}
+2
View File
@@ -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
}
+2
View File
@@ -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
}
+2
View File
@@ -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
}
+2
View File
@@ -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
}
@@ -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)
}
}
@@ -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)
}
}
@@ -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)
}
}
@@ -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)
}
}
@@ -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
@@ -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 }
@@ -0,0 +1,6 @@
roles:
r1: r1 name
r2: r2 name
r3: r3 name
r4: r4 name
r5: r5 name
@@ -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 }
@@ -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
@@ -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 }
@@ -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
@@ -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 }