@@ -75,36 +75,88 @@ func helloWorldAct(ctx context.Context) (string, error) {
75
75
return "test" , nil
76
76
}
77
77
78
- func helloWorldActivityWorkflow (ctx Context , input string ) (result string , err error ) {
79
- ao := ActivityOptions {
80
- ScheduleToStartTimeout : 10 * time .Second ,
81
- StartToCloseTimeout : 5 * time .Second ,
82
- HeartbeatTimeout : 2 * time .Second ,
83
- ActivityID : "id1" ,
84
- TaskList : tasklist ,
85
- }
86
- ctx1 := WithActivityOptions (ctx , ao )
87
- f := ExecuteActivity (ctx1 , helloWorldAct )
88
- var r1 string
89
- err = f .Get (ctx , & r1 )
90
- if err != nil {
91
- return "" , err
92
- }
93
- return r1 , nil
94
- }
95
-
96
78
type key int
97
79
98
80
const unitTestKey key = 1
99
81
100
- func (s * WorkflowUnitTest ) Test_SingleActivityWorkflow () {
82
+ func singleActivityWorkflowWithOptions (s * WorkflowUnitTest , ao ActivityOptions ) error {
83
+ helloWorldActivityWorkflow := func (ctx Context , input string ) (result string , err error ) {
84
+ ctx1 := WithActivityOptions (ctx , ao )
85
+ f := ExecuteActivity (ctx1 , helloWorldAct )
86
+ var r1 string
87
+ err = f .Get (ctx , & r1 )
88
+ if err != nil {
89
+ return "" , err
90
+ }
91
+ return r1 , nil
92
+ }
93
+
101
94
env := newTestWorkflowEnv (s .T ())
102
95
ctx := context .WithValue (context .Background (), unitTestKey , s )
103
96
env .SetWorkerOptions (WorkerOptions {BackgroundActivityContext : ctx })
104
97
env .RegisterActivity (helloWorldAct )
105
98
env .ExecuteWorkflow (helloWorldActivityWorkflow , "Hello" )
106
99
s .True (env .IsWorkflowCompleted ())
107
- s .NoError (env .GetWorkflowError ())
100
+ return env .GetWorkflowError ()
101
+ }
102
+
103
+ func (s * WorkflowUnitTest ) Test_SingleActivityWorkflow () {
104
+ ao := ActivityOptions {
105
+ ScheduleToStartTimeout : 10 * time .Second ,
106
+ StartToCloseTimeout : 5 * time .Second ,
107
+ HeartbeatTimeout : 2 * time .Second ,
108
+ ActivityID : "id1" ,
109
+ TaskList : tasklist ,
110
+ }
111
+ err := singleActivityWorkflowWithOptions (s , ao )
112
+ s .NoError (err )
113
+ }
114
+
115
+ func (s * WorkflowUnitTest ) Test_SingleActivityWorkflowIsErrorMessagesMatched () {
116
+ testCases := []struct {
117
+ name string
118
+ ScheduleToStartTimeout time.Duration
119
+ StartToCloseTimeout time.Duration
120
+ ScheduleToCloseTimeout time.Duration
121
+ expectedErrorMessage string
122
+ }{
123
+ {
124
+ name : "ZeroScheduleToStartTimeout" ,
125
+ ScheduleToStartTimeout : 0 * time .Second ,
126
+ StartToCloseTimeout : 5 * time .Second ,
127
+ ScheduleToCloseTimeout : 0 * time .Second ,
128
+ expectedErrorMessage : "missing or negative ScheduleToStartTimeoutSeconds" ,
129
+ },
130
+ {
131
+ name : "ZeroStartToCloseTimeout" ,
132
+ ScheduleToStartTimeout : 10 * time .Second ,
133
+ StartToCloseTimeout : 0 * time .Second ,
134
+ ScheduleToCloseTimeout : 0 * time .Second ,
135
+ expectedErrorMessage : "missing or negative StartToCloseTimeoutSeconds" ,
136
+ },
137
+ {
138
+ name : "NegativeScheduleToCloseTimeout" ,
139
+ ScheduleToStartTimeout : 10 * time .Second ,
140
+ StartToCloseTimeout : 5 * time .Second ,
141
+ ScheduleToCloseTimeout : - 1 * time .Second ,
142
+ expectedErrorMessage : "invalid negative ScheduleToCloseTimeoutSeconds" ,
143
+ },
144
+ }
145
+
146
+ for _ , testCase := range testCases {
147
+ ao := ActivityOptions {
148
+ ScheduleToStartTimeout : testCase .ScheduleToStartTimeout ,
149
+ StartToCloseTimeout : testCase .StartToCloseTimeout ,
150
+ ScheduleToCloseTimeout : testCase .ScheduleToCloseTimeout ,
151
+ HeartbeatTimeout : 2 * time .Second ,
152
+ ActivityID : "id1" ,
153
+ TaskList : tasklist ,
154
+ }
155
+ s .Run (testCase .name , func () {
156
+ err := singleActivityWorkflowWithOptions (s , ao )
157
+ s .ErrorContains (err , testCase .expectedErrorMessage )
158
+ })
159
+ }
108
160
}
109
161
110
162
func splitJoinActivityWorkflow (ctx Context , testPanic bool ) (result string , err error ) {
0 commit comments