Skip to content

Commit

Permalink
Improve docs and tests for HandlerUnfinishedPolicy (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Aug 14, 2024
1 parent 0b7928d commit c3ac511
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
// HandlerUnfinishedPolicy actions taken if a workflow completes with running handlers.
//
// Policy defining actions taken when a workflow exits while update or signal handlers are running.
// The workflow exit may be due to successful return, failure, cancellation, or continue-as-new
// The workflow exit may be due to successful return, cancellation, or continue-as-new
type HandlerUnfinishedPolicy int

const (
Expand Down Expand Up @@ -2368,4 +2368,4 @@ func (wc *workflowEnvironmentInterceptor) ExecuteNexusOperation(ctx Context, cli

func (wc *workflowEnvironmentInterceptor) RequestCancelNexusOperation(ctx Context, input RequestCancelNexusOperationInput) {
wc.env.RequestCancelNexusOperation(input.seq)
}
}
26 changes: 25 additions & 1 deletion internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {
})
}, time.Minute)

env.RegisterDelayedCallback(func() {
env.UpdateWorkflow("nonWarningHandler", "id_3", &updateCallback{
reject: func(err error) {
require.Fail(t, "update should not be rejected")
},
accept: func() {},
complete: func(interface{}, error) {},
})
}, 2*time.Minute)

env.RegisterDelayedCallback(func() {
if completionType == "cancel" {
env.CancelWorkflow()
Expand All @@ -596,6 +606,20 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {
return 0, err
}

err = SetUpdateHandler(ctx, "nonWarningHandler", func(ctx Context) error {
inflightUpdates++
ranUpdates++
defer func() {
inflightUpdates--
}()
return Sleep(ctx, time.Hour)
}, UpdateHandlerOptions{
UnfinishedPolicy: HandlerUnfinishedPolicyAbandon,
})
if err != nil {
return 0, err
}

var completeType string
s := NewSelector(ctx)
s.AddReceive(ctx.Done(), func(c ReceiveChannel, more bool) {
Expand Down Expand Up @@ -671,7 +695,7 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {
var buf bytes.Buffer
result, err := runWf("complete", &buf)
require.NoError(t, err)
require.Equal(t, 2, result)
require.Equal(t, 3, result)
assertExpectedLogs(t, &buf, true)
})
t.Run("cancel", func(t *testing.T) {
Expand Down

0 comments on commit c3ac511

Please sign in to comment.