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

Improve docs and tests for HandlerUnfinishedPolicy #1589

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
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
Loading