Skip to content

Commit 5a861df

Browse files
committed
Fix ValidateUpdateWorkflowStateStatus() added more tests
1 parent 16e3147 commit 5a861df

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

common/persistence/workflow_state_status_validator.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,19 @@ func ValidateUpdateWorkflowStateStatus(
6767
}
6868

6969
// validate workflow state & status
70-
if (state == enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED && status == enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING) ||
71-
(state != enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED && (status != enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING && status != enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED)) {
72-
return serviceerror.NewInternalf("Update workflow with invalid state: %v or status: %v", state, status)
70+
switch state {
71+
case enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING:
72+
if status != enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING && status != enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED {
73+
return serviceerror.NewInternalf("Update workflow with invalid state: %v or status: %v", state, status)
74+
}
75+
case enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE:
76+
if status != enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING {
77+
return serviceerror.NewInternalf("Update workflow with invalid state: %v or status: %v", state, status)
78+
}
79+
default:
80+
if status == enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING || status == enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED {
81+
return serviceerror.NewInternalf("Update workflow with invalid state: %v or status: %v", state, status)
82+
}
7383
}
7484
return nil
7585
}

common/persistence/workflow_state_status_validator_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,26 @@ func (s *workflowStateStatusSuite) TestCreateWorkflowStateStatus_WorkflowStateZo
111111
}
112112

113113
func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateCreated() {
114-
statuses := []enumspb.WorkflowExecutionStatus{
114+
disallowedStatuses := []enumspb.WorkflowExecutionStatus{
115115
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
116116
enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
117117
enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
118118
enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
119119
enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
120120
enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
121+
enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED,
121122
}
122123

124+
// Updating workflow to State: CREATED and status: RUNNING is allowed
123125
s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
124126

125-
for _, status := range statuses {
127+
for _, status := range disallowedStatuses {
126128
s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_CREATED, status))
127129
}
128130
}
129131

130132
func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateRunning() {
131-
statuses := []enumspb.WorkflowExecutionStatus{
133+
disallowedStatuses := []enumspb.WorkflowExecutionStatus{
132134
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
133135
enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
134136
enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
@@ -137,15 +139,17 @@ func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateRu
137139
enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
138140
}
139141

142+
// Updating workflow to State: RUNNING and status: {RUNNING, PAUSED} is allowed
140143
s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
144+
s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED))
141145

142-
for _, status := range statuses {
146+
for _, status := range disallowedStatuses {
143147
s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING, status))
144148
}
145149
}
146150

147151
func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateCompleted() {
148-
statuses := []enumspb.WorkflowExecutionStatus{
152+
allowedStatuses := []enumspb.WorkflowExecutionStatus{
149153
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
150154
enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
151155
enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
@@ -154,26 +158,29 @@ func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateCo
154158
enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
155159
}
156160

161+
// Updating workflow to State: COMPLETED and status: {RUNNING, PAUSED} is *not* allowed
157162
s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
163+
s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED))
158164

159-
for _, status := range statuses {
165+
for _, status := range allowedStatuses {
160166
s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED, status))
161167
}
162168
}
163169

164170
func (s *workflowStateStatusSuite) TestUpdateWorkflowStateStatus_WorkflowStateZombie() {
165-
statuses := []enumspb.WorkflowExecutionStatus{
171+
disallowedStatuses := []enumspb.WorkflowExecutionStatus{
166172
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
167173
enumspb.WORKFLOW_EXECUTION_STATUS_FAILED,
168174
enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED,
169175
enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED,
170176
enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW,
171177
enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT,
178+
enumspb.WORKFLOW_EXECUTION_STATUS_PAUSED,
172179
}
173180

174181
s.NoError(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING))
175182

176-
for _, status := range statuses {
183+
for _, status := range disallowedStatuses {
177184
s.Error(ValidateUpdateWorkflowStateStatus(enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE, status))
178185
}
179186
}

service/history/workflow/workflow_task_state_machine.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,6 @@ func (m *workflowTaskStateMachine) UpdateWorkflowTask(
10281028

10291029
// NOTE:
10301030
// - do not update executionInfo.TaskQueue!
1031-
// - do not update executionInfo.WorkflowTaskStamp (only changed when rescheduling workflow task)
10321031

10331032
m.ms.logger.Debug("Workflow task updated",
10341033
tag.WorkflowScheduledEventID(workflowTask.ScheduledEventID),

0 commit comments

Comments
 (0)