Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/internal_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,9 @@ func getFunctionName(i interface{}) (name string, isMethod bool) {
}

func getActivityFunctionName(r *registry, i interface{}) string {
if name, ok := i.(string); ok {
return name
}
result, _ := getFunctionName(i)
Comment thread
dplyukhin marked this conversation as resolved.
if alias, ok := r.getActivityAlias(result); ok {
result = alias
Expand Down
37 changes: 37 additions & 0 deletions internal/internal_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,43 @@ func TestAliasUnqualifiedNameClash(t *testing.T) {
require.Equal(t, "func1", executeWorkflow(true))
}

// These structs intentionally have activities with the same short name. Setting an
// alias should allow us to disambiguate them.
type aliasReproV1 struct{}
func (aliasReproV1) MyActivity(context.Context) (string, error) { return "func1", nil }
type aliasReproV2 struct{}
func (aliasReproV2) MyActivity(context.Context) (string, error) { return "func2", nil }

func TestAliasAntialiasing(t *testing.T) {
w := func(ctx Context) (string, error) {
ctx = WithActivityOptions(ctx, ActivityOptions{ScheduleToCloseTimeout: 5 * time.Second})
var str1 string
if err := ExecuteActivity(ctx, "MyActivity").Get(ctx, &str1); err != nil {
return "", err
}
var str2 string
if err := ExecuteActivity(ctx, "MyActivity_v2").Get(ctx, &str2); err != nil {
return "", err
}
return str1 + "-" + str2, nil
Comment thread
dplyukhin marked this conversation as resolved.
}

executeWorkflow := func() (result string) {
var suite WorkflowTestSuite
env := suite.NewTestWorkflowEnvironment()
env.RegisterActivity(aliasReproV1{}.MyActivity)
env.RegisterActivityWithOptions(
aliasReproV2{}.MyActivity,
RegisterActivityOptions{Name: "MyActivity_v2"},
)
env.ExecuteWorkflow(w)
require.NoError(t, env.GetWorkflowResult(&result))
return
}

require.Equal(t, "func1-func2", executeWorkflow())
}

func (s *internalWorkerTestSuite) TestReservedTemporalName() {
// workflow
worker := createWorker(s.service)
Expand Down
Loading