Skip to content

Commit c3ac511

Browse files
authoredAug 14, 2024··
Improve docs and tests for HandlerUnfinishedPolicy (#1589)
1 parent 0b7928d commit c3ac511

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
 

‎internal/workflow.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
// HandlerUnfinishedPolicy actions taken if a workflow completes with running handlers.
4949
//
5050
// Policy defining actions taken when a workflow exits while update or signal handlers are running.
51-
// The workflow exit may be due to successful return, failure, cancellation, or continue-as-new
51+
// The workflow exit may be due to successful return, cancellation, or continue-as-new
5252
type HandlerUnfinishedPolicy int
5353

5454
const (
@@ -2368,4 +2368,4 @@ func (wc *workflowEnvironmentInterceptor) ExecuteNexusOperation(ctx Context, cli
23682368

23692369
func (wc *workflowEnvironmentInterceptor) RequestCancelNexusOperation(ctx Context, input RequestCancelNexusOperationInput) {
23702370
wc.env.RequestCancelNexusOperation(input.seq)
2371-
}
2371+
}

‎internal/workflow_testsuite_test.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,16 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {
573573
})
574574
}, time.Minute)
575575

576+
env.RegisterDelayedCallback(func() {
577+
env.UpdateWorkflow("nonWarningHandler", "id_3", &updateCallback{
578+
reject: func(err error) {
579+
require.Fail(t, "update should not be rejected")
580+
},
581+
accept: func() {},
582+
complete: func(interface{}, error) {},
583+
})
584+
}, 2*time.Minute)
585+
576586
env.RegisterDelayedCallback(func() {
577587
if completionType == "cancel" {
578588
env.CancelWorkflow()
@@ -596,6 +606,20 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {
596606
return 0, err
597607
}
598608

609+
err = SetUpdateHandler(ctx, "nonWarningHandler", func(ctx Context) error {
610+
inflightUpdates++
611+
ranUpdates++
612+
defer func() {
613+
inflightUpdates--
614+
}()
615+
return Sleep(ctx, time.Hour)
616+
}, UpdateHandlerOptions{
617+
UnfinishedPolicy: HandlerUnfinishedPolicyAbandon,
618+
})
619+
if err != nil {
620+
return 0, err
621+
}
622+
599623
var completeType string
600624
s := NewSelector(ctx)
601625
s.AddReceive(ctx.Done(), func(c ReceiveChannel, more bool) {
@@ -671,7 +695,7 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {
671695
var buf bytes.Buffer
672696
result, err := runWf("complete", &buf)
673697
require.NoError(t, err)
674-
require.Equal(t, 2, result)
698+
require.Equal(t, 3, result)
675699
assertExpectedLogs(t, &buf, true)
676700
})
677701
t.Run("cancel", func(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.