Skip to content

Commit

Permalink
Merge 8c5a987 into fe1eba2
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobweinstock authored Jul 6, 2022
2 parents fe1eba2 + 8c5a987 commit 632e166
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/dbserver_worker_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *DBServer) ReportActionStatus(ctx context.Context, req *workflow.Workflo
}
}

if wfContext.TotalNumberOfActions > 1 && actionIndex == wfContext.TotalNumberOfActions-1 {
if wfContext.TotalNumberOfActions > 1 && actionIndex >= wfContext.TotalNumberOfActions {
return nil, status.Errorf(codes.FailedPrecondition, errInvalidActionIndex)
}

Expand Down
97 changes: 97 additions & 0 deletions server/dbserver_worker_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,103 @@ func TestReportActionStatus(t *testing.T) {
expectedError: false,
},
},
"report status for final action": {
args: args{
db: &mock.DB{
GetWorkflowContextsFunc: func(ctx context.Context, wfID string) (*pb.WorkflowContext, error) {
return &pb.WorkflowContext{
WorkflowId: workflowID,
TotalNumberOfActions: 2,
CurrentActionState: pb.State_STATE_RUNNING,
CurrentAction: actionName,
}, nil
},
GetWorkflowActionsFunc: func(ctx context.Context, wfID string) (*pb.WorkflowActionList, error) {
return &pb.WorkflowActionList{
ActionList: []*pb.WorkflowAction{
{
WorkerId: workerID,
Image: actionName,
Name: "first-action",
Timeout: int64(90),
TaskName: taskName,
},
{
WorkerId: workerID,
Image: actionName,
Name: actionName,
Timeout: int64(90),
TaskName: taskName,
},
},
}, nil
},
UpdateWorkflowStateFunc: func(ctx context.Context, wfContext *pb.WorkflowContext) error {
return nil
},
InsertIntoWorkflowEventTableFunc: func(ctx context.Context, wfEvent *pb.WorkflowActionStatus, time time.Time) error {
return nil
},
},
workflowID: workflowID,
workerID: workerID,
taskName: taskName,
actionName: actionName,
actionState: pb.State_STATE_RUNNING,
},
want: want{
expectedError: false,
},
},
"report status for after final action": {
args: args{
db: &mock.DB{
GetWorkflowContextsFunc: func(ctx context.Context, wfID string) (*pb.WorkflowContext, error) {
return &pb.WorkflowContext{
WorkflowId: workflowID,
TotalNumberOfActions: 2,
CurrentActionState: pb.State_STATE_SUCCESS,
CurrentAction: actionName,
CurrentActionIndex: 2,
}, nil
},
GetWorkflowActionsFunc: func(ctx context.Context, wfID string) (*pb.WorkflowActionList, error) {
return &pb.WorkflowActionList{
ActionList: []*pb.WorkflowAction{
{
WorkerId: workerID,
Image: actionName,
Name: "first-action",
Timeout: int64(90),
TaskName: taskName,
},
{
WorkerId: workerID,
Image: actionName,
Name: actionName,
Timeout: int64(90),
TaskName: taskName,
},
},
}, nil
},
UpdateWorkflowStateFunc: func(ctx context.Context, wfContext *pb.WorkflowContext) error {
return nil
},
InsertIntoWorkflowEventTableFunc: func(ctx context.Context, wfEvent *pb.WorkflowActionStatus, time time.Time) error {
return nil
},
},
workflowID: workflowID,
workerID: workerID,
taskName: taskName,
actionName: actionName,
actionState: pb.State_STATE_RUNNING,
},
want: want{
expectedError: true,
},
},
"report status for second action": {
args: args{
db: &mock.DB{
Expand Down

0 comments on commit 632e166

Please sign in to comment.