Skip to content

Commit 1d5bd15

Browse files
authored
bugfix: registered activity with alias in test suite (#344)
* bugfix: registered activity with alias in test suite
1 parent 083e254 commit 1d5bd15

File tree

6 files changed

+44
-24
lines changed

6 files changed

+44
-24
lines changed

internal/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func NewCanceledError(details ...interface{}) *CanceledError {
188188
//
189189
func NewContinueAsNewError(ctx Context, wfn interface{}, args ...interface{}) *ContinueAsNewError {
190190
// Validate type and its arguments.
191-
workflowType, input, err := getValidatedWorkerFunction(wfn, args)
191+
workflowType, input, err := getValidatedWorkflowFunction(wfn, args)
192192
if err != nil {
193193
panic(err)
194194
}

internal/internal_workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ func newWorkflowDefinition(workflow workflow) workflowDefinition {
942942
return &syncWorkflowDefinition{workflow: workflow}
943943
}
944944

945-
func getValidatedWorkerFunction(workflowFunc interface{}, args []interface{}) (*WorkflowType, []byte, error) {
945+
func getValidatedWorkflowFunction(workflowFunc interface{}, args []interface{}) (*WorkflowType, []byte, error) {
946946
fnName := ""
947947
fType := reflect.TypeOf(workflowFunc)
948948
switch fType.Kind() {

internal/internal_workflow_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (wc *workflowClient) StartWorkflow(
153153
}
154154

155155
// Validate type and its arguments.
156-
workflowType, input, err := getValidatedWorkerFunction(workflowFunc, args)
156+
workflowType, input, err := getValidatedWorkflowFunction(workflowFunc, args)
157157
if err != nil {
158158
return nil, err
159159
}

internal/internal_workflow_testsuite.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -298,25 +298,11 @@ func (env *testWorkflowEnvironmentImpl) setActivityTaskList(tasklist string, act
298298
}
299299

300300
func (env *testWorkflowEnvironmentImpl) executeWorkflow(workflowFn interface{}, args ...interface{}) {
301-
var workflowType string
302-
fnType := reflect.TypeOf(workflowFn)
303-
switch fnType.Kind() {
304-
case reflect.String:
305-
workflowType = workflowFn.(string)
306-
case reflect.Func:
307-
workflowType = getFunctionName(workflowFn)
308-
if alias, ok := getHostEnvironment().getWorkflowAlias(workflowType); ok {
309-
workflowType = alias
310-
}
311-
default:
312-
panic("unsupported workflowFn")
313-
}
314-
315-
input, err := getHostEnvironment().encodeArgs(args)
301+
workflowType, input, err := getValidatedWorkflowFunction(workflowFn, args)
316302
if err != nil {
317303
panic(err)
318304
}
319-
env.executeWorkflowInternal(workflowType, input)
305+
env.executeWorkflowInternal(workflowType.Name, input)
320306
}
321307

322308
func (env *testWorkflowEnvironmentImpl) executeWorkflowInternal(workflowType string, input []byte) {
@@ -353,15 +339,13 @@ func (env *testWorkflowEnvironmentImpl) executeActivity(
353339
activityFn interface{},
354340
args ...interface{},
355341
) (encoded.Value, error) {
356-
fnName := getFunctionName(activityFn)
357-
358-
input, err := getHostEnvironment().encodeArgs(args)
342+
activityType, input, err := getValidatedActivityFunction(activityFn, args)
359343
if err != nil {
360344
panic(err)
361345
}
362346

363347
params := executeActivityParameters{
364-
ActivityType: ActivityType{Name: fnName},
348+
ActivityType: *activityType,
365349
Input: input,
366350
ScheduleToCloseTimeoutSeconds: 600,
367351
StartToCloseTimeoutSeconds: 600,

internal/internal_workflow_testsuite_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,42 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityWithThriftTypes() {
959959
s.EqualValues(expectedValues, actualValues)
960960
}
961961

962+
func (s *WorkflowTestSuiteUnitTest) Test_ActivityRegistration() {
963+
activityFn := func(msg string) (string, error) {
964+
return msg, nil
965+
}
966+
activityAlias := "some-random-activity-alias"
967+
968+
RegisterActivityWithOptions(activityFn, RegisterActivityOptions{Name: activityAlias})
969+
env := s.NewTestActivityEnvironment()
970+
input := "some random input"
971+
972+
encodedValue, err := env.ExecuteActivity(activityFn, input)
973+
s.NoError(err)
974+
output := ""
975+
encodedValue.Get(&output)
976+
s.Equal(input, output)
977+
978+
encodedValue, err = env.ExecuteActivity(activityAlias, input)
979+
s.NoError(err)
980+
output = ""
981+
encodedValue.Get(&output)
982+
s.Equal(input, output)
983+
}
984+
985+
func (s *WorkflowTestSuiteUnitTest) Test_WorkflowRegistration() {
986+
workflowFn := func(ctx Context) error {
987+
return nil
988+
}
989+
workflowAlias := "some-random-workflow-alias"
990+
991+
RegisterWorkflowWithOptions(workflowFn, RegisterWorkflowOptions{Name: workflowAlias})
992+
env := s.NewTestWorkflowEnvironment()
993+
994+
env.ExecuteWorkflow(workflowFn)
995+
env.ExecuteWorkflow(workflowAlias)
996+
}
997+
962998
func (s *WorkflowTestSuiteUnitTest) Test_ActivityFriendlyName() {
963999
activityFn := func(msg string) (string, error) {
9641000
return "hello_" + msg, nil

internal/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func ExecuteChildWorkflow(ctx Context, childWorkflow interface{}, args ...interf
359359
result := childWorkflowFutureImpl{
360360
decodeFutureImpl: mainFuture.(*decodeFutureImpl),
361361
executionFuture: executionFuture.(*futureImpl)}
362-
wfType, input, err := getValidatedWorkerFunction(childWorkflow, args)
362+
wfType, input, err := getValidatedWorkflowFunction(childWorkflow, args)
363363
if err != nil {
364364
mainSettable.Set(nil, err)
365365
return result

0 commit comments

Comments
 (0)