-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathebb_and_flow_test.go
More file actions
148 lines (124 loc) · 3.95 KB
/
ebb_and_flow_test.go
File metadata and controls
148 lines (124 loc) · 3.95 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package scenarios
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/temporalio/omes/cmd/clioptions"
"github.com/temporalio/omes/loadgen"
"github.com/temporalio/omes/workers"
)
func TestEbbAndFlowRateMode(t *testing.T) {
t.Parallel()
env := workers.SetupTestEnvironment(t,
workers.WithExecutorTimeout(2*time.Minute))
scenarioInfo := loadgen.ScenarioInfo{
RunID: fmt.Sprintf("eaf-rate-%d", time.Now().Unix()),
Configuration: loadgen.RunConfiguration{
Duration: 10 * time.Second,
},
ScenarioOptions: map[string]string{
MinAddRateFlag: "1",
MaxAddRateFlag: "3",
RatePeriodFlag: "5s",
MinBacklogFlag: "0",
MaxBacklogFlag: "3",
BacklogPeriodFlag: "5s",
PeriodFlag: "5s",
BacklogLogIntervalFlag: "5s",
VisibilityVerificationTimeoutFlag: "5s",
},
}
executor := newEbbAndFlowExecutor()
_, err := env.RunExecutorTest(t, executor, scenarioInfo, clioptions.LangGo)
require.NoError(t, err, "Rate mode executor should complete successfully")
state := executor.Snapshot().(ebbAndFlowState)
require.GreaterOrEqual(t, state.TotalCompletedWorkflows, int64(1))
}
func TestEbbAndFlow(t *testing.T) {
t.Parallel()
env := workers.SetupTestEnvironment(t,
workers.WithExecutorTimeout(2*time.Minute))
sleepActivityJson := `{
"count": {
"type": "fixed",
"value": "5"
},
"groups": {
"group_a": {
"weight": 1,
"sleepDuration": {
"type": "fixed",
"value": "1ms"
},
"fairnessKeys": {
"type": "fixed",
"value": "1"
}
},
"group_b": {
"weight": 1,
"sleepDuration": {
"type": "fixed",
"value": "1ms"
},
"fairnessKeys": {
"type": "fixed",
"value": "2"
}
}
}
}`
scenarioInfo := loadgen.ScenarioInfo{
RunID: fmt.Sprintf("eaf-%d", time.Now().Unix()),
Configuration: loadgen.RunConfiguration{
Duration: 10 * time.Second,
},
ScenarioOptions: map[string]string{
MinBacklogFlag: "0",
MaxBacklogFlag: "1",
PeriodFlag: "5s",
BacklogLogIntervalFlag: "5s",
VisibilityVerificationTimeoutFlag: "5s",
SleepActivityJsonFlag: sleepActivityJson,
},
}
var state ebbAndFlowState
t.Run("Run executor", func(t *testing.T) {
executor := newEbbAndFlowExecutor()
_, err := env.RunExecutorTest(t, executor, scenarioInfo, clioptions.LangGo)
require.NoError(t, err, "Executor should complete successfully")
state = executor.Snapshot().(ebbAndFlowState)
require.GreaterOrEqual(t, state.TotalCompletedWorkflows, int64(1))
})
t.Run("Run executor again, resuming from previous state", func(t *testing.T) {
executor := newEbbAndFlowExecutor()
// Load previous state
previouState := state
err := executor.LoadState(func(v any) error {
s := v.(*ebbAndFlowState)
*s = state
return nil
})
require.NoError(t, err, "Should be able to load previous state")
resumeScenarioInfo := scenarioInfo
_, err = env.RunExecutorTest(t, executor, resumeScenarioInfo, clioptions.LangGo)
require.NoError(t, err, "Executor should complete successfully")
state = executor.Snapshot().(ebbAndFlowState)
require.Greater(t, state.TotalCompletedWorkflows, previouState.TotalCompletedWorkflows)
})
t.Run("Run executor again, resuming from previous state but without any time left", func(t *testing.T) {
executor := newEbbAndFlowExecutor()
// Load previous state
err := executor.LoadState(func(v any) error {
s := v.(*ebbAndFlowState)
*s = state
return nil
})
require.NoError(t, err, "Should be able to load previous state")
resumeScenarioInfo := scenarioInfo
resumeScenarioInfo.Configuration.Duration = 0 // ie no more time left
_, err = env.RunExecutorTest(t, executor, resumeScenarioInfo, clioptions.LangGo)
require.NoError(t, err, "Executor should complete successfully")
})
}