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

Expand arguments in UpdateWorkflow call when args equal one #1799

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion internal/workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,12 @@ func (e *TestWorkflowEnvironment) UpdateWorkflowNoRejection(updateName string, u
OnAccept: func() {},
OnComplete: func(interface{}, error) {},
}
e.UpdateWorkflow(updateName, updateID, uc, args)

if len(args) == 1 {
disco07 marked this conversation as resolved.
Show resolved Hide resolved
e.UpdateWorkflow(updateName, updateID, uc, args...)
} else {
e.UpdateWorkflow(updateName, updateID, uc, args)
}
}

// QueryWorkflowByID queries a child workflow by its ID and returns the result synchronously
Expand Down
70 changes: 70 additions & 0 deletions internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,76 @@ func TestWorkflowUpdateOrder(t *testing.T) {
require.Equal(t, 1, result)
}

func TestWorkflowUpdateOrderWithOneArg(t *testing.T) {
var suite WorkflowTestSuite
// Test UpdateWorkflowByID works with custom ID and additional arguments
env := suite.NewTestWorkflowEnvironment()
env.RegisterDelayedCallback(func() {
env.UpdateWorkflowNoRejection("update", "id", t, "args")
}, 0)

env.ExecuteWorkflow(func(ctx Context) (int, error) {
var inflightUpdates int
var ranUpdates int
err := SetUpdateHandler(ctx, "update", func(ctx Context, args string) error {
inflightUpdates++
ranUpdates++
defer func() {
inflightUpdates--
}()

require.Equal(t, "args", args)

return Sleep(ctx, time.Hour)
}, UpdateHandlerOptions{})
if err != nil {
return 0, err
}
err = Await(ctx, func() bool { return inflightUpdates == 0 })
return ranUpdates, err
})

require.NoError(t, env.GetWorkflowError())
var result int
require.NoError(t, env.GetWorkflowResult(&result))
require.Equal(t, 1, result)
}

func TestWorkflowUpdateOrderWithMultiArgs(t *testing.T) {
var suite WorkflowTestSuite
// Test UpdateWorkflowByID works with custom ID and additional arguments
env := suite.NewTestWorkflowEnvironment()
env.RegisterDelayedCallback(func() {
env.UpdateWorkflowNoRejection("update", "id", t, "args1", "args2")
}, 0)

env.ExecuteWorkflow(func(ctx Context) (int, error) {
var inflightUpdates int
var ranUpdates int
err := SetUpdateHandler(ctx, "update", func(ctx Context, args []string) error {
inflightUpdates++
ranUpdates++
defer func() {
inflightUpdates--
}()

require.Equal(t, args, []string{"args1", "args2"})

return Sleep(ctx, time.Hour)
}, UpdateHandlerOptions{})
if err != nil {
return 0, err
}
err = Await(ctx, func() bool { return inflightUpdates == 0 })
return ranUpdates, err
})

require.NoError(t, env.GetWorkflowError())
var result int
require.NoError(t, env.GetWorkflowResult(&result))
require.Equal(t, 1, result)
}

func TestWorkflowUpdateIdGeneration(t *testing.T) {
var suite WorkflowTestSuite
env := suite.NewTestWorkflowEnvironment()
Expand Down