From 246f699ea9a61eb748902a41d7c03a215a058749 Mon Sep 17 00:00:00 2001 From: parauliya Date: Thu, 15 Apr 2021 17:06:15 +0530 Subject: [PATCH] Fixed review comments and unit tests Signed-off-by: parauliya --- grpc-server/workflow.go | 15 ++++++++++----- grpc-server/workflow_test.go | 8 ++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/grpc-server/workflow.go b/grpc-server/workflow.go index 86850abfd..400c14b70 100644 --- a/grpc-server/workflow.go +++ b/grpc-server/workflow.go @@ -274,13 +274,18 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo return nil } +// This function will provide the workflow state on the basis of the state of the actions +// For e.g. : If an action has Tailed or Timeout then the workflow state will also be +// considered as Failed/Timeout. And If an action is successfull then the workflow state +// will be considered as Running until the last action of the workflow is executed successfully. + func getWorkflowState(db db.Database, ctx context.Context, id string) workflow.State { - wfctx, _ := db.GetWorkflowContexts(ctx, id) - if wfctx.CurrentActionState != workflow.State_STATE_SUCCESS { - return wfctx.CurrentActionState + wfCtx, _ := db.GetWorkflowContexts(ctx, id) + if wfCtx.CurrentActionState != workflow.State_STATE_SUCCESS { + return wfCtx.CurrentActionState } else { - wfacts, _ := db.GetWorkflowActions(ctx, id) - if isLastAction(wfctx, wfacts) { + //wfacts, _ := db.GetWorkflowActions(ctx, id) + if wfCtx.GetCurrentActionIndex() == wfCtx.GetTotalNumberOfActions()-1 { return workflow.State_STATE_SUCCESS } else { return workflow.State_STATE_RUNNING diff --git a/grpc-server/workflow_test.go b/grpc-server/workflow_test.go index 8efcdca8c..334c653ae 100644 --- a/grpc-server/workflow_test.go +++ b/grpc-server/workflow_test.go @@ -136,6 +136,14 @@ func TestGetWorkflow(t *testing.T) { Template: templateID, Hardware: hw}, nil }, + GetWorkflowContextsFunc: func(ctx context.Context, wfID string) (*workflow.WorkflowContext, error) { + return &workflow.WorkflowContext{ + WorkflowId: wfID, + CurrentActionState: workflow.State_STATE_SUCCESS, + CurrentActionIndex: 0, + TotalNumberOfActions: 1, + }, nil + }, GetTemplateFunc: func(ctx context.Context, fields map[string]string, deleted bool) (string, string, string, error) { return "", "", templateData, nil },