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

Document ambiguous ID and test for mismatch on signal start #612

Merged
merged 5 commits into from
Nov 15, 2021
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ vet: $(ALL_SRC)
go vet ./...

staticcheck: $(ALL_SRC)
GO111MODULE=off go get -u honnef.co/go/tools/cmd/staticcheck
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...

errcheck: $(ALL_SRC)
Expand Down
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ type (
// If the workflow is not running or not found, it starts the workflow and then sends the signal in transaction.
// - workflowID, signalName, signalArg are same as SignalWorkflow's parameters
// - options, workflow, workflowArgs are same as StartWorkflow's parameters
// - the workflowID parameter is used instead of options.ID. If the latter is present, it must match the workflowID.
// Note: options.WorkflowIDReusePolicy is default to AllowDuplicate in this API.
// The errors it can return:
// - serviceerror.NotFound, if namespace does not exist
Expand Down
1 change: 1 addition & 0 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type (
// If the workflow is not running or not found, it starts the workflow and then sends the signal in transaction.
// - workflowID, signalName, signalArg are same as SignalWorkflow's parameters
// - options, workflow, workflowArgs are same as StartWorkflow's parameters
// - the workflowID parameter is used instead of options.ID. If the latter is present, it must match the workflowID.
// Note: options.WorkflowIDReusePolicy is default to AllowDuplicate.
// The errors it can return:
// - serviceerror.NotFound, if namespace does not exist
Expand Down
9 changes: 8 additions & 1 deletion internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,14 @@ func (wc *WorkflowClient) SignalWorkflow(ctx context.Context, workflowID string,
func (wc *WorkflowClient) SignalWithStartWorkflow(ctx context.Context, workflowID string, signalName string, signalArg interface{},
options StartWorkflowOptions, workflowFunc interface{}, workflowArgs ...interface{}) (WorkflowRun, error) {

// Default workflow ID
// Due to the ambiguous way to provide workflow IDs, if options contains an
// ID, it must match the parameter
if options.ID != "" && options.ID != workflowID {
return nil, fmt.Errorf("workflow ID from options not used, must be unset or match workflow ID parameter")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change.
I think it's necessary but we should document this in the release notes and mark it as breaking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a breaking change if you consider extra validation of (unbeknownst) improper param setting as a breaking change. It went from being an invalid param do the wrong thing to an invalid param error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware, but this still could result in a change of behavior in some rare cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Ok, I will make sure to document in the release notes

}

// Default workflow ID to UUID
options.ID = workflowID
if options.ID == "" {
options.ID = uuid.New()
}
Expand Down
12 changes: 10 additions & 2 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ func (s *workflowClientTestSuite) TestSignalWithStartWorkflow() {
s.Nil(err)
s.Equal(startResponse.GetRunId(), resp.GetRunID())

options.ID = ""
resp, err = s.client.SignalWithStartWorkflow(context.Background(), "", signalName, signalInput,
options, workflowType)
s.Nil(err)
Expand Down Expand Up @@ -1073,7 +1074,14 @@ func (s *workflowClientTestSuite) TestSignalWithStartWorkflowWithContextAwareDat
s.Equal(startResponse.GetRunId(), resp.GetRunID())
}

func (s *workflowClientTestSuite) TestExecuteWorkflow() {
func (s *workflowClientTestSuite) TestSignalWithStartWorkflowAmbiguousID() {
_, err := s.client.SignalWithStartWorkflow(context.Background(), "workflow-id-1", "my-signal", "my-signal-value",
StartWorkflowOptions{ID: "workflow-id-2"}, workflowType)
s.Error(err)
s.Contains(err.Error(), "workflow ID from options not used")
}

func (s *workflowClientTestSuite) TestStartWorkflow() {
client, ok := s.client.(*WorkflowClient)
s.True(ok)
options := StartWorkflowOptions{
Expand Down Expand Up @@ -1208,7 +1216,7 @@ func (s *workflowClientTestSuite) TestSignalWithStartWorkflowWithMemoAndSearchAt
"testAttr": "attr value",
}
options := StartWorkflowOptions{
ID: workflowID,
ID: "wid",
TaskQueue: taskqueue,
WorkflowExecutionTimeout: timeoutInSeconds,
WorkflowTaskTimeout: timeoutInSeconds,
Expand Down