forked from temporalio/temporal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_test.go
More file actions
69 lines (53 loc) · 1.76 KB
/
buffer_test.go
File metadata and controls
69 lines (53 loc) · 1.76 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
package effect_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.temporal.io/server/common/effect"
)
func TestBufferApplyOrder(t *testing.T) {
var buf effect.Buffer
state := make([]int, 0, 3)
buf.OnAfterCommit(func(context.Context) { state = append(state, 0) })
buf.OnAfterCommit(func(context.Context) { state = append(state, 1) })
buf.OnAfterCommit(func(context.Context) { state = append(state, 2) })
buf.Apply(context.TODO())
require.ElementsMatch(t, []int{0, 1, 2}, state)
}
func TestBufferRollbackOrder(t *testing.T) {
var buf effect.Buffer
state := make([]int, 0, 3)
buf.OnAfterRollback(func(context.Context) { state = append(state, 0) })
buf.OnAfterRollback(func(context.Context) { state = append(state, 1) })
buf.OnAfterRollback(func(context.Context) { state = append(state, 2) })
buf.Cancel(context.TODO())
require.ElementsMatch(t, []int{2, 1, 0}, state)
}
func TestBufferCancelAfterApply(t *testing.T) {
var buf effect.Buffer
var commit, rollback int
buf.OnAfterCommit(func(context.Context) { commit++ })
buf.OnAfterRollback(func(context.Context) { rollback++ })
buf.Apply(context.TODO())
buf.Cancel(context.TODO())
buf.Apply(context.TODO())
buf.Cancel(context.TODO())
buf.Apply(context.TODO())
buf.Cancel(context.TODO())
require.Equal(t, commit, 1)
require.Equal(t, rollback, 0)
}
func TestBufferApplyAfterCancel(t *testing.T) {
var buf effect.Buffer
var commit, rollback int
buf.OnAfterCommit(func(context.Context) { commit++ })
buf.OnAfterRollback(func(context.Context) { rollback++ })
buf.Cancel(context.TODO())
buf.Apply(context.TODO())
buf.Apply(context.TODO())
buf.Cancel(context.TODO())
buf.Apply(context.TODO())
buf.Cancel(context.TODO())
require.Equal(t, commit, 0)
require.Equal(t, rollback, 1)
}