-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuite.go
More file actions
160 lines (125 loc) · 3.63 KB
/
suite.go
File metadata and controls
160 lines (125 loc) · 3.63 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
149
150
151
152
153
154
155
156
157
158
159
160
package testcases
import (
"context"
"strings"
"testing"
"time"
"github.com/makasim/flowstate"
"go.uber.org/goleak"
)
type Suite struct {
SetUp func(t *testing.T) flowstate.Driver
SetUpDelayer bool
disableGoleak bool
cases map[string]func(t *testing.T, e *flowstate.Engine, fr flowstate.FlowRegistry, d flowstate.Driver)
}
func (s *Suite) Test(main *testing.T) {
for name := range s.cases {
s.run(main, name)
}
}
func (s *Suite) run(main *testing.T, name string) {
if !s.disableGoleak {
defer goleak.VerifyNone(main, goleak.IgnoreCurrent())
}
main.Run(name, func(t *testing.T) {
t.Helper()
fn := s.cases[name]
if fn == nil {
t.SkipNow()
}
l, _ := NewTestLogger(t)
d := s.SetUp(t)
fr := &flowstate.DefaultFlowRegistry{}
e, err := flowstate.NewEngine(d, fr, l)
if err != nil {
t.Fatalf("failed to create engine: %v", err)
}
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
t.Fatalf("failed to shutdown engine: %v", err)
}
})
if s.SetUpDelayer {
dlr, err := flowstate.NewDelayer(e, l)
if err != nil {
t.Fatalf("failed to create delayer: %v", err)
}
t.Cleanup(func() {
sCtx, sCtxCancel := context.WithTimeout(context.Background(), time.Second*5)
defer sCtxCancel()
if err := dlr.Shutdown(sCtx); err != nil {
t.Fatalf("failed to shutdown delayer: %v", err)
}
})
}
fn(t, e, fr, d)
})
}
func (s *Suite) DisableGoleak() {
s.disableGoleak = true
}
func (s *Suite) Skip(t *testing.T, name string) {
if _, ok := s.cases[name]; !ok {
t.Fatal("unknown test case: ", name)
}
s.cases[name] = nil
}
func Get(setUp func(t *testing.T) flowstate.Driver) *Suite {
return &Suite{
SetUp: setUp,
SetUpDelayer: true,
cases: map[string]func(t *testing.T, e *flowstate.Engine, fr flowstate.FlowRegistry, d flowstate.Driver){
"Actor": Actor,
"CallFlow": CallFlow,
"CallFlowWithCommit": CallFlowWithCommit,
"CallFlowWithWatch": CallFlowWithWatch,
"Condition": Condition,
"DataFlowConfig": DataFlowConfig,
"DataStoreGet": DataStoreGet,
"DataStoreGetWithCommit": DataStoreGetWithCommit,
"Delay": Delay,
"Fork": Fork,
"ForkJoinFirstWins": ForkJoin_FirstWins,
"ForkJoinLastWins": ForkJoin_LastWins,
"ForkWithCommit": Fork_WithCommit,
"GetOneByIDAndRev": GetOneByIDAndRev,
"GetOneLatestByID": GetOneLatestByID,
"GetOneLatestByLabel": GetOneLatestByLabel,
"GetOneNotFound": GetOneNotFound,
"GetManyLabels": GetManyLabels,
"GetManyOrLabels": GetManyORLabels,
"GetManySinceLatest": GetManySinceLatest,
"GetManySinceRev": GetManySinceRev,
"GetManySinceTime": GetManySinceTime,
"GetManyLatestOnly": GetManyLatestOnly,
"Mutex": Mutex,
"Queue": Queue,
"RateLimit": RateLimit,
"SingleNode": SingleNode,
"ThreeConsequentNodes": ThreeConsequentNodes,
"TwoConsequentNodes": TwoConsequentNodes,
"TwoConsequentNodesWithCommit": TwoConsequentNodesWithCommit,
"WatchLabels": WatchLabels,
"WatchOrLabels": WatchORLabels,
"WatchSinceLatest": WatchSinceLatest,
"WatchSinceRev": WatchSinceRev,
"WatchSinceTime": WatchSinceTime,
"Cron": Cron,
"StoreData": StoreData,
"GetData": GetData,
},
}
}
func filterSystemStates(states []flowstate.State) []flowstate.State {
res := make([]flowstate.State, 0, len(states))
for _, s := range states {
if strings.HasPrefix(string(s.ID), "flowstate.") {
continue
}
res = append(res, s)
}
return res
}