-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathtester_workflowinfo_test.go
More file actions
95 lines (68 loc) · 2.94 KB
/
tester_workflowinfo_test.go
File metadata and controls
95 lines (68 loc) · 2.94 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
package tester
import (
"context"
"testing"
"github.com/cschleiden/go-workflows/workflow"
"github.com/stretchr/testify/require"
)
func Test_InstanceExecutionDetails_HistoryLength(t *testing.T) {
var capturedLength int64
workflowWithInfo := func(ctx workflow.Context) error {
info := workflow.InstanceExecutionDetails(ctx)
capturedLength = info.HistoryLength
return nil
}
tester := NewWorkflowTester[any](workflowWithInfo)
tester.Execute(context.Background())
require.True(t, tester.WorkflowFinished())
require.Positive(t, capturedLength, "History length should be greater than 0")
}
func Test_InstanceExecutionDetails_HistoryLength_WithActivity(t *testing.T) {
var lengthBeforeActivity, lengthAfterActivity int64
workflowWithActivity := func(ctx workflow.Context) (int, error) {
info := workflow.InstanceExecutionDetails(ctx)
lengthBeforeActivity = info.HistoryLength
r, err := workflow.ExecuteActivity[int](ctx, workflow.DefaultActivityOptions, activity1).Get(ctx)
if err != nil {
return 0, err
}
info = workflow.InstanceExecutionDetails(ctx)
lengthAfterActivity = info.HistoryLength
return r, nil
}
tester := NewWorkflowTester[int](workflowWithActivity)
tester.Registry().RegisterActivity(activity1)
tester.Execute(context.Background())
require.True(t, tester.WorkflowFinished())
require.Positive(t, lengthBeforeActivity)
require.Greater(t, lengthAfterActivity, lengthBeforeActivity, "History length should increase after activity execution")
r, err := tester.WorkflowResult()
require.NoError(t, err)
require.Equal(t, 23, r)
}
func Test_InstanceExecutionDetails_HistoryLength_MultipleSteps(t *testing.T) {
var lengths []int64
workflowMultipleSteps := func(ctx workflow.Context) error {
info := workflow.InstanceExecutionDetails(ctx)
lengths = append(lengths, info.HistoryLength)
workflow.ExecuteActivity[int](ctx, workflow.DefaultActivityOptions, activity1).Get(ctx)
info = workflow.InstanceExecutionDetails(ctx)
lengths = append(lengths, info.HistoryLength)
workflow.ExecuteActivity[int](ctx, workflow.DefaultActivityOptions, activity1).Get(ctx)
info = workflow.InstanceExecutionDetails(ctx)
lengths = append(lengths, info.HistoryLength)
return nil
}
tester := NewWorkflowTester[any](workflowMultipleSteps)
tester.Registry().RegisterActivity(activity1)
tester.Execute(context.Background())
require.True(t, tester.WorkflowFinished())
// The tester replays the workflow, so we'll see the lengths multiple times
// We just need to verify that the final three captures show increasing values
require.GreaterOrEqual(t, len(lengths), 3, "Should have at least 3 length captures")
// Get the last 3 values (from the final execution)
finalLengths := lengths[len(lengths)-3:]
require.Positive(t, finalLengths[0])
require.Greater(t, finalLengths[1], finalLengths[0], "History should grow after first activity")
require.Greater(t, finalLengths[2], finalLengths[1], "History should grow after second activity")
}