forked from temporalio/temporal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory_event_test.go
More file actions
111 lines (103 loc) · 3.04 KB
/
history_event_test.go
File metadata and controls
111 lines (103 loc) · 3.04 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
package testing
import (
"fmt"
"runtime/debug"
"testing"
"github.com/stretchr/testify/suite"
historypb "go.temporal.io/api/history/v1"
)
type (
historyEventTestSuit struct {
suite.Suite
generator Generator
}
)
func TestHistoryEventTestSuite(t *testing.T) {
suite.Run(t, new(historyEventTestSuit))
}
func (s *historyEventTestSuit) SetupSuite() {
s.generator = InitializeHistoryEventGenerator("namespace", "ns-id", 1)
}
func (s *historyEventTestSuit) SetupTest() {
s.generator.Reset()
}
// This is a sample about how to use the generator
func (s *historyEventTestSuit) Test_HistoryEvent_Generator() {
defer func() {
if r := recover(); r != nil {
fmt.Println("stacktrace from panic: \n" + string(debug.Stack()))
}
}()
maxEventID := int64(0)
maxVersion := int64(1)
maxTaskID := int64(1)
for i := 0; i < 10 && s.generator.HasNextVertex(); i++ {
events := s.generator.GetNextVertices()
fmt.Println("########################")
for _, e := range events {
event := e.GetData().(*historypb.HistoryEvent)
if maxEventID != event.GetEventId()-1 {
s.Fail("event id sequence is incorrect")
}
maxEventID = event.GetEventId()
if maxVersion > event.GetVersion() {
s.Fail("event version is incorrect")
}
maxVersion = event.GetVersion()
if maxTaskID > event.GetTaskId() {
s.Fail("event task id is incorrect")
}
maxTaskID = event.GetTaskId()
fmt.Println(e.GetName())
fmt.Println(event.GetEventId())
}
}
s.NotEmpty(s.generator.ListGeneratedVertices())
fmt.Println("==========================")
branchGenerator1 := s.generator.DeepCopy()
for i := 0; i < 10 && branchGenerator1.HasNextVertex(); i++ {
events := branchGenerator1.GetNextVertices()
fmt.Println("########################")
for _, e := range events {
event := e.GetData().(*historypb.HistoryEvent)
if maxEventID != event.GetEventId()-1 {
s.Fail("event id sequence is incorrect")
}
maxEventID = event.GetEventId()
if maxVersion > event.GetVersion() {
s.Fail("event version is incorrect")
}
maxVersion = event.GetVersion()
if maxTaskID > event.GetTaskId() {
s.Fail("event task id is incorrect")
}
maxTaskID = event.GetTaskId()
fmt.Println(e.GetName())
fmt.Println(event.GetEventId())
}
}
fmt.Println("==========================")
history := s.generator.ListGeneratedVertices()
maxEventID = history[len(history)-1].GetData().(*historypb.HistoryEvent).GetEventId()
for i := 0; i < 10 && s.generator.HasNextVertex(); i++ {
events := s.generator.GetNextVertices()
fmt.Println("########################")
for _, e := range events {
event := e.GetData().(*historypb.HistoryEvent)
if maxEventID != event.GetEventId()-1 {
s.Fail("event id sequence is incorrect")
}
maxEventID = event.GetEventId()
if maxVersion > event.GetVersion() {
s.Fail("event version is incorrect")
}
maxVersion = event.GetVersion()
if maxTaskID > event.GetTaskId() {
s.Fail("event task id is incorrect")
}
maxTaskID = event.GetTaskId()
fmt.Println(e.GetName())
fmt.Println(event.GetEventId())
}
}
}