-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_many_latest_only.go
61 lines (48 loc) · 1.31 KB
/
get_many_latest_only.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
54
55
56
57
58
59
60
61
package testcases
import (
"context"
"time"
"github.com/makasim/flowstate"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
func GetManyLatestOnly(t TestingT, d flowstate.Doer, _ FlowRegistry) {
defer goleak.VerifyNone(t, goleak.IgnoreCurrent())
l, _ := NewTestLogger(t)
e, err := flowstate.NewEngine(d, l)
require.NoError(t, err)
defer func() {
sCtx, sCtxCancel := context.WithTimeout(context.Background(), time.Second*5)
defer sCtxCancel()
require.NoError(t, e.Shutdown(sCtx))
}()
stateCtx := &flowstate.StateCtx{
Current: flowstate.State{
ID: "aTID",
},
}
stateCtx1 := &flowstate.StateCtx{
Current: flowstate.State{
ID: "anotherTID",
},
}
for i := 0; i < 3; i++ {
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(stateCtx),
)))
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(stateCtx1),
)))
}
cmd := flowstate.GetManyByLabels(nil).WithLatestOnly()
require.NoError(t, e.Do(cmd))
res, err := cmd.Result()
require.NoError(t, err)
require.Len(t, res.States, 2)
require.False(t, res.More)
actStates := res.States
require.Equal(t, flowstate.StateID(`aTID`), actStates[0].ID)
require.Equal(t, int64(5), actStates[0].Rev)
require.Equal(t, flowstate.StateID(`anotherTID`), actStates[1].ID)
require.Equal(t, int64(6), actStates[1].Rev)
}