Skip to content

Commit 5a23998

Browse files
authored
Corrected error messages in getValidatedActivityOptions (#1224)
* Improved error messages in getValidatedActivityOptions, also removed redundant call to getActivityOptions * Added tests for the error messages in getValidatedActivityOptions * Rolled back to the previous error messages and transformed the three new tests into a table test
1 parent e5063a1 commit 5a23998

File tree

3 files changed

+74
-23
lines changed

3 files changed

+74
-23
lines changed

internal/internal_activity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func getValidatedActivityOptions(ctx Context) (*activityOptions, error) {
187187
return nil, errors.New("missing or negative StartToCloseTimeoutSeconds")
188188
}
189189
if p.ScheduleToCloseTimeoutSeconds < 0 {
190-
return nil, errors.New("missing or negative ScheduleToCloseTimeoutSeconds")
190+
return nil, errors.New("invalid negative ScheduleToCloseTimeoutSeconds")
191191
}
192192
if p.ScheduleToCloseTimeoutSeconds == 0 {
193193
// This is a optional parameter, we default to sum of the other two timeouts.

internal/internal_workflow_test.go

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,88 @@ func helloWorldAct(ctx context.Context) (string, error) {
7575
return "test", nil
7676
}
7777

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-
9678
type key int
9779

9880
const unitTestKey key = 1
9981

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+
10194
env := newTestWorkflowEnv(s.T())
10295
ctx := context.WithValue(context.Background(), unitTestKey, s)
10396
env.SetWorkerOptions(WorkerOptions{BackgroundActivityContext: ctx})
10497
env.RegisterActivity(helloWorldAct)
10598
env.ExecuteWorkflow(helloWorldActivityWorkflow, "Hello")
10699
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+
}
108160
}
109161

110162
func splitJoinActivityWorkflow(ctx Context, testPanic bool) (result string, err error) {

internal/workflow.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@ func (wc *workflowEnvironmentInterceptor) ExecuteActivity(ctx Context, typeName
743743
return future
744744
}
745745
// Validate context options.
746-
options := getActivityOptions(ctx)
747-
options, err = getValidatedActivityOptions(ctx)
746+
options, err := getValidatedActivityOptions(ctx)
748747
if err != nil {
749748
settable.Set(nil, err)
750749
return future

0 commit comments

Comments
 (0)