Skip to content

Commit 93c915a

Browse files
committed
Reject updates when the workflow is paused
1 parent 22bcab3 commit 93c915a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

service/history/api/updateworkflow/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func (u *Updater) ApplyRequest(
124124
return nil, consts.ErrWorkflowCompleted
125125
}
126126

127+
// We don't accept the request to update the workflow if the workflow is paused.
128+
if ms.IsWorkflowExecutionStatusPaused() {
129+
return nil, serviceerror.NewFailedPrecondition("Workflow is paused. Cannot update the workflow.")
130+
}
131+
127132
if ms.GetExecutionInfo().WorkflowTaskAttempt >= failUpdateWorkflowTaskAttemptCount {
128133
// If workflow task is constantly failing, the update to that workflow will also fail.
129134
// Additionally, workflow update can't "fix" workflow state because updates (delivered with messages)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package updateworkflow
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
"go.temporal.io/api/serviceerror"
9+
updatepb "go.temporal.io/api/update/v1"
10+
"go.temporal.io/api/workflowservice/v1"
11+
"go.temporal.io/server/api/historyservice/v1"
12+
"go.temporal.io/server/common/definition"
13+
historyi "go.temporal.io/server/service/history/interfaces"
14+
"go.temporal.io/server/service/history/workflow/update"
15+
"go.uber.org/mock/gomock"
16+
)
17+
18+
func TestApplyRequest_RejectsUpdateOnPausedWorkflow(t *testing.T) {
19+
t.Parallel()
20+
21+
ctrl := gomock.NewController(t)
22+
23+
ms := historyi.NewMockMutableState(ctrl)
24+
ms.EXPECT().GetWorkflowKey().Return(definition.NewWorkflowKey("ns-id", "wf-id", "run-id"))
25+
ms.EXPECT().IsWorkflowExecutionRunning().Return(true)
26+
ms.EXPECT().IsWorkflowExecutionStatusPaused().Return(true)
27+
// Required by update.NewRegistry
28+
ms.EXPECT().GetCurrentVersion().Return(int64(1))
29+
ms.EXPECT().VisitUpdates(gomock.Any())
30+
31+
updateReg := update.NewRegistry(ms)
32+
33+
updater := &Updater{
34+
req: createUpdateRequest("test-update-id"),
35+
}
36+
37+
action, err := updater.ApplyRequest(context.Background(), updateReg, ms)
38+
39+
require.Nil(t, action)
40+
require.Error(t, err)
41+
var failedPrecondition *serviceerror.FailedPrecondition
42+
require.ErrorAs(t, err, &failedPrecondition)
43+
require.Contains(t, err.Error(), "Workflow is paused")
44+
}
45+
46+
func createUpdateRequest(updateID string) *historyservice.UpdateWorkflowExecutionRequest {
47+
return &historyservice.UpdateWorkflowExecutionRequest{
48+
Request: &workflowservice.UpdateWorkflowExecutionRequest{
49+
Request: &updatepb.Request{
50+
Meta: &updatepb.Meta{
51+
UpdateId: updateID,
52+
},
53+
},
54+
},
55+
}
56+
}

0 commit comments

Comments
 (0)