/
workflow_test.go
82 lines (63 loc) · 2.07 KB
/
workflow_test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package workertaskqueue
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"go.temporal.io/sdk/testsuite"
"go.temporal.io/sdk/worker"
)
type unitTestSuite struct {
suite.Suite
testsuite.WorkflowTestSuite
env *testsuite.TestWorkflowEnvironment
}
func (t *unitTestSuite) SetupTest() {
t.env = t.NewTestWorkflowEnvironment()
}
func (t *unitTestSuite) AfterTest(suiteName, testName string) {
t.env.AssertExpectations(t.T())
}
// Run all the tests in the suite
func Test_UnitTestSuite(t *testing.T) {
suite.Run(t, new(unitTestSuite))
}
func (t *unitTestSuite) Test_Simple() {
env := t.NewTestWorkflowEnvironment()
env.RegisterWorkflow(TaskQWorkflow)
env.SetWorkerOptions(worker.Options{
EnableSessionWorker: true, // Important for a worker to participate in the session
EnableLoggingInReplay: true,
})
t1 := &Task{
Id: "task-1",
Priority: 1,
CallbackId: "workflow-id",
CallbackSignalName: requestSignalName,
}
env.RegisterDelayedCallback(func() {
env.SignalWorkflow(requestSignalName, t1)
}, 0)
t2 := &Task{
Id: "task-2",
Priority: 1,
CallbackId: "workflow-id",
CallbackSignalName: requestSignalName,
}
env.RegisterDelayedCallback(func() {
env.SignalWorkflow(requestSignalName, t2)
}, 10*time.Second)
env.OnActivity(activities.ProcessTask, mock.Anything, mock.Anything).Return(t1, nil).Times(1)
env.OnSignalExternalWorkflow("default-test-namespace", "workflow-id", "", requestSignalName, mock.MatchedBy(func(v *Task) bool { return true })).Return(nil).Times(1)
env.OnActivity(activities.ProcessTask, mock.Anything, mock.Anything).Return(t2, nil).Times(1)
env.OnSignalExternalWorkflow("default-test-namespace", "workflow-id", "", requestSignalName, mock.MatchedBy(func(v *Task) bool { return true })).Return(nil).Times(1)
env.ExecuteWorkflow(TaskQWorkflow)
t.True(env.IsWorkflowCompleted())
t.NoError(env.GetWorkflowError())
err := env.GetWorkflowError()
if err != nil {
fmt.Println(err)
}
env.AssertExpectations(t.T())
}