Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow replayer to use local activities with string names #745

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions internal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package internal

import (
"context"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -629,11 +630,16 @@ func (wc *workflowEnvironmentInterceptor) ExecuteLocalActivity(ctx Context, type
return future
}
activity, ok := registry.GetActivity(activityType.Name)
if !ok {
if ok {
activityFn = activity.GetFunction()
} else if IsReplayNamespace(GetWorkflowInfo(ctx).Namespace) {
// When running the replayer (but not necessarily during all replays), we
// don't require the activities to be registered, so use a dummy function
activityFn = func(context.Context) error { panic("dummy replayer function") }
} else {
settable.Set(nil, fmt.Errorf("local activity %s is not registered by the worker", activityType.Name))
return future
}
activityFn = activity.GetFunction()
} else {
if err := validateFunctionArgs(localCtx.fn, args, false); err != nil {
settable.Set(nil, err)
Expand Down
27 changes: 27 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,33 @@ func (ts *IntegrationTestSuite) TestReturnCancelError() {
ts.Equal(enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED, resp.GetWorkflowExecutionInfo().GetStatus())
}

func (ts *IntegrationTestSuite) TestLocalActivityStringNameReplay() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Run the workflow
run, err := ts.client.ExecuteWorkflow(ctx,
ts.startWorkflowOptions("test-local-activity-string-name-replay"), ts.workflows.LocalActivityByStringName)
ts.NotNil(run)
ts.NoError(err)
ts.NoError(run.Get(ctx, nil))

// Obtain history
var history historypb.History
iter := ts.client.GetWorkflowHistory(ctx, run.GetID(), run.GetRunID(), false,
enumspb.HISTORY_EVENT_FILTER_TYPE_ALL_EVENT)
for iter.HasNext() {
event, err := iter.Next()
ts.NoError(err)
history.Events = append(history.Events, event)
}

// Run in replayer
replayer := worker.NewWorkflowReplayer()
replayer.RegisterWorkflow(ts.workflows.LocalActivityByStringName)
ts.NoError(replayer.ReplayWorkflowHistory(nil, &history))
}

func (ts *IntegrationTestSuite) TestMaxConcurrentSessionExecutionSize() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
6 changes: 6 additions & 0 deletions test/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,11 @@ func (w *Workflows) ReturnCancelError(
return temporal.NewCanceledError("some details")
}

func (w *Workflows) LocalActivityByStringName(ctx workflow.Context) error {
ctx = workflow.WithLocalActivityOptions(ctx, w.defaultLocalActivityOptions())
return workflow.ExecuteLocalActivity(ctx, "Prefix_ToUpper", "somestring").Get(ctx, nil)
}

func (w *Workflows) register(worker worker.Worker) {
worker.RegisterWorkflow(w.ActivityCancelRepro)
worker.RegisterWorkflow(w.ActivityCompletionUsingID)
Expand Down Expand Up @@ -1791,6 +1796,7 @@ func (w *Workflows) register(worker worker.Worker) {
worker.RegisterWorkflow(w.TooFewParams)
worker.RegisterWorkflow(w.ExecuteRemoteActivityToUpper)
worker.RegisterWorkflow(w.ReturnCancelError)
worker.RegisterWorkflow(w.LocalActivityByStringName)

worker.RegisterWorkflow(w.child)
worker.RegisterWorkflow(w.childForMemoAndSearchAttr)
Expand Down