forked from temporalio/omes
/
kitchen_sink_executor.go
53 lines (45 loc) · 1.45 KB
/
kitchen_sink_executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package loadgen
import (
"context"
"github.com/golang/protobuf/proto"
"github.com/temporalio/omes/loadgen/kitchensink"
)
type KitchenSinkExecutor struct {
TestInput *kitchensink.TestInput
// Called once on start
PrepareTestInput func(context.Context, ScenarioInfo, *kitchensink.TestInput) error
// Called for each iteration. TestInput is copied entirely into KitchenSinkWorkflowOptions on
// each iteration.
UpdateWorkflowOptions func(context.Context, *Run, *KitchenSinkWorkflowOptions) error
DefaultConfiguration RunConfiguration
}
func (k KitchenSinkExecutor) Run(ctx context.Context, info ScenarioInfo) error {
if k.PrepareTestInput != nil {
if err := k.PrepareTestInput(ctx, info, k.TestInput); err != nil {
return err
}
}
// Create generic executor and run it
ge := &GenericExecutor{
DefaultConfiguration: k.DefaultConfiguration,
Execute: func(ctx context.Context, run *Run) error {
options := run.DefaultKitchenSinkWorkflowOptions()
testInputClone, ok := proto.Clone(k.TestInput).(*kitchensink.TestInput)
if !ok {
panic("failed to clone test input")
}
options.Params = testInputClone
if k.UpdateWorkflowOptions != nil {
err := k.UpdateWorkflowOptions(ctx, run, &options)
if err != nil {
return err
}
}
return run.ExecuteKitchenSinkWorkflow(ctx, &options)
},
}
return ge.Run(ctx, info)
}
func (k KitchenSinkExecutor) GetDefaultConfiguration() RunConfiguration {
return k.DefaultConfiguration
}