Skip to content

Commit 6e75f6d

Browse files
disco07yuandrew
andauthored
Expand arguments in UpdateWorkflow call when args equal one (#1799)
* Expand arguments in UpdateWorkflow call when args equal one * remove duration * expand variadic --------- Co-authored-by: Andrew Yuan <[email protected]>
1 parent 24542f7 commit 6e75f6d

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

internal/workflow_testsuite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,8 @@ func (e *TestWorkflowEnvironment) UpdateWorkflowNoRejection(updateName string, u
11331133
OnAccept: func() {},
11341134
OnComplete: func(interface{}, error) {},
11351135
}
1136-
e.UpdateWorkflow(updateName, updateID, uc, args)
1136+
1137+
e.UpdateWorkflow(updateName, updateID, uc, args...)
11371138
}
11381139

11391140
// QueryWorkflowByID queries a child workflow by its ID and returns the result synchronously

internal/workflow_testsuite_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,77 @@ func TestWorkflowUpdateOrder(t *testing.T) {
395395
require.Equal(t, 1, result)
396396
}
397397

398+
func TestWorkflowUpdateOrderWithOneArg(t *testing.T) {
399+
var suite WorkflowTestSuite
400+
// Test UpdateWorkflowByID works with custom ID and additional arguments
401+
env := suite.NewTestWorkflowEnvironment()
402+
env.RegisterDelayedCallback(func() {
403+
env.UpdateWorkflowNoRejection("update", "id", t, "args")
404+
}, 0)
405+
406+
env.ExecuteWorkflow(func(ctx Context) (int, error) {
407+
var inflightUpdates int
408+
var ranUpdates int
409+
err := SetUpdateHandler(ctx, "update", func(ctx Context, args string) error {
410+
inflightUpdates++
411+
ranUpdates++
412+
defer func() {
413+
inflightUpdates--
414+
}()
415+
416+
require.Equal(t, "args", args)
417+
418+
return Sleep(ctx, time.Hour)
419+
}, UpdateHandlerOptions{})
420+
if err != nil {
421+
return 0, err
422+
}
423+
err = Await(ctx, func() bool { return inflightUpdates == 0 })
424+
return ranUpdates, err
425+
})
426+
427+
require.NoError(t, env.GetWorkflowError())
428+
var result int
429+
require.NoError(t, env.GetWorkflowResult(&result))
430+
require.Equal(t, 1, result)
431+
}
432+
433+
func TestWorkflowUpdateOrderWithMultiArgs(t *testing.T) {
434+
var suite WorkflowTestSuite
435+
// Test UpdateWorkflowByID works with custom ID and additional arguments
436+
env := suite.NewTestWorkflowEnvironment()
437+
env.RegisterDelayedCallback(func() {
438+
env.UpdateWorkflowNoRejection("update", "id", t, "args1", "args2")
439+
}, 0)
440+
441+
env.ExecuteWorkflow(func(ctx Context) (int, error) {
442+
var inflightUpdates int
443+
var ranUpdates int
444+
err := SetUpdateHandler(ctx, "update", func(ctx Context, args1, args2 string) error {
445+
inflightUpdates++
446+
ranUpdates++
447+
defer func() {
448+
inflightUpdates--
449+
}()
450+
451+
require.Equal(t, args1, "args1")
452+
require.Equal(t, args2, "args2")
453+
454+
return Sleep(ctx, time.Hour)
455+
}, UpdateHandlerOptions{})
456+
if err != nil {
457+
return 0, err
458+
}
459+
err = Await(ctx, func() bool { return inflightUpdates == 0 })
460+
return ranUpdates, err
461+
})
462+
463+
require.NoError(t, env.GetWorkflowError())
464+
var result int
465+
require.NoError(t, env.GetWorkflowResult(&result))
466+
require.Equal(t, 1, result)
467+
}
468+
398469
func TestWorkflowUpdateIdGeneration(t *testing.T) {
399470
var suite WorkflowTestSuite
400471
env := suite.NewTestWorkflowEnvironment()

0 commit comments

Comments
 (0)