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