-
Notifications
You must be signed in to change notification settings - Fork 198
/
goroutine_workflow_test.go
46 lines (36 loc) · 1.07 KB
/
goroutine_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
package goroutine
import (
"fmt"
"github.com/stretchr/testify/suite"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/testsuite"
"sort"
"testing"
)
type UnitTestSuite struct {
suite.Suite
testsuite.WorkflowTestSuite
}
func TestUnitTestSuite(t *testing.T) {
suite.Run(t, new(UnitTestSuite))
}
func Step1Test(input string) (output string, err error) {
return input + ", Step1", nil
}
func Step2Test(input string) (output string, err error) {
return input + ", Step2", nil
}
func (s *UnitTestSuite) Test_GoroutineWorkflow() {
env := s.NewTestWorkflowEnvironment()
env.RegisterActivityWithOptions(Step1Test, activity.RegisterOptions{Name: "Step1"})
env.RegisterActivityWithOptions(Step2Test, activity.RegisterOptions{Name: "Step2"})
env.ExecuteWorkflow(SampleGoroutineWorkflow, 2)
s.True(env.IsWorkflowCompleted())
s.NoError(env.GetWorkflowError())
var result []string
_ = env.GetWorkflowResult(&result)
fmt.Println(result)
sort.Strings(result) // Order of goroutine execution is not defined
s.Equal("0, Step1, Step2", result[0])
s.Equal("1, Step1, Step2", result[1])
}