From 3ba74ecdf49434164e62025ce1c9286744b1cf84 Mon Sep 17 00:00:00 2001 From: Ketan Umare Date: Fri, 29 May 2020 16:56:19 -0700 Subject: [PATCH] bug; abort called for not started nodes --- pkg/controller/nodes/executor.go | 13 +++++++++++ pkg/controller/nodes/executor_test.go | 32 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/pkg/controller/nodes/executor.go b/pkg/controller/nodes/executor.go index 75d56749d..ad25e4cb1 100644 --- a/pkg/controller/nodes/executor.go +++ b/pkg/controller/nodes/executor.go @@ -669,6 +669,12 @@ func (c *nodeExecutor) FinalizeHandler(ctx context.Context, execContext executor nodeStatus := nl.GetNodeExecutionStatus(ctx, currentNode.GetID()) nodePhase := nodeStatus.GetPhase() + if nodePhase == v1alpha1.NodePhaseNotYetStarted { + logger.Infof(ctx, "Node not yet started, will not finalize") + // Nothing to be aborted + return nil + } + if canHandleNode(nodePhase) { ctx = contextutils.WithNodeID(ctx, currentNode.GetID()) @@ -721,6 +727,13 @@ func (c *nodeExecutor) FinalizeHandler(ctx context.Context, execContext executor func (c *nodeExecutor) AbortHandler(ctx context.Context, execContext executors.ExecutionContext, dag executors.DAGStructure, nl executors.NodeLookup, currentNode v1alpha1.ExecutableNode, reason string) error { nodeStatus := nl.GetNodeExecutionStatus(ctx, currentNode.GetID()) nodePhase := nodeStatus.GetPhase() + + if nodePhase == v1alpha1.NodePhaseNotYetStarted { + logger.Infof(ctx, "Node not yet started, will not finalize") + // Nothing to be aborted + return nil + } + if canHandleNode(nodePhase) { ctx = contextutils.WithNodeID(ctx, currentNode.GetID()) diff --git a/pkg/controller/nodes/executor_test.go b/pkg/controller/nodes/executor_test.go index 458db7762..36bd42e3e 100644 --- a/pkg/controller/nodes/executor_test.go +++ b/pkg/controller/nodes/executor_test.go @@ -1523,3 +1523,35 @@ func Test_nodeExecutor_abort(t *testing.T) { assert.True(t, called) }) } + +func TestNodeExecutor_AbortHandler(t *testing.T) { + ctx := context.Background() + exec := nodeExecutor{} + + t.Run("not-yet-started", func(t *testing.T) { + id := "id" + n := &mocks.ExecutableNode{} + n.OnGetID().Return(id) + nl := &mocks4.NodeLookup{} + ns := &mocks.ExecutableNodeStatus{} + ns.OnGetPhase().Return(v1alpha1.NodePhaseNotYetStarted) + nl.OnGetNodeExecutionStatusMatch(mock.Anything, id).Return(ns) + assert.NoError(t, exec.AbortHandler(ctx, nil, nil, nl, n, "aborting")) + }) +} + +func TestNodeExecutor_FinalizeHandler(t *testing.T) { + ctx := context.Background() + exec := nodeExecutor{} + + t.Run("not-yet-started", func(t *testing.T) { + id := "id" + n := &mocks.ExecutableNode{} + n.OnGetID().Return(id) + nl := &mocks4.NodeLookup{} + ns := &mocks.ExecutableNodeStatus{} + ns.OnGetPhase().Return(v1alpha1.NodePhaseNotYetStarted) + nl.OnGetNodeExecutionStatusMatch(mock.Anything, id).Return(ns) + assert.NoError(t, exec.FinalizeHandler(ctx, nil, nil, nl, n)) + }) +}