TestProcessNodeRetries tests the processNodeRetries() method.
(t *testing.T)
| 518 | |
| 519 | // TestProcessNodeRetries tests the processNodeRetries() method. |
| 520 | func TestProcessNodeRetries(t *testing.T) { |
| 521 | cancel, controller := newController(logging.TestContext(t.Context())) |
| 522 | defer cancel() |
| 523 | assert.NotNil(t, controller) |
| 524 | wf := wfv1.MustUnmarshalWorkflow(helloWorldWf) |
| 525 | assert.NotNil(t, wf) |
| 526 | ctx := logging.TestContext(t.Context()) |
| 527 | woc := newWorkflowOperationCtx(ctx, wf, controller) |
| 528 | assert.NotNil(t, woc) |
| 529 | // Verify that there are no nodes in the wf status. |
| 530 | assert.Empty(t, woc.wf.Status.Nodes) |
| 531 | |
| 532 | // Add the parent node for retries. |
| 533 | nodeName := "test-node" |
| 534 | nodeID := woc.wf.NodeID(nodeName) |
| 535 | node := woc.initializeNode(ctx, nodeName, wfv1.NodeTypeRetry, "", &wfv1.WorkflowStep{}, "", wfv1.NodeRunning, &wfv1.NodeFlag{}, true) |
| 536 | retries := wfv1.RetryStrategy{} |
| 537 | retries.Limit = intstrutil.ParsePtr("2") |
| 538 | woc.wf.Status.Nodes[nodeID] = *node |
| 539 | |
| 540 | assert.Equal(t, wfv1.NodeRunning, node.Phase) |
| 541 | |
| 542 | // Ensure there are no child nodes yet. |
| 543 | lastChild := getChildNodeIndex(node, woc.wf.Status.Nodes, -1) |
| 544 | assert.Nil(t, lastChild) |
| 545 | |
| 546 | // Add child nodes. |
| 547 | for i := 0; i < 2; i++ { |
| 548 | childNode := fmt.Sprintf("%s(%d)", nodeName, i) |
| 549 | woc.initializeNode(ctx, childNode, wfv1.NodeTypePod, "", &wfv1.WorkflowStep{}, "", wfv1.NodeRunning, &wfv1.NodeFlag{Retried: true}, true) |
| 550 | woc.addChildNode(ctx, nodeName, childNode) |
| 551 | } |
| 552 | |
| 553 | n, err := woc.wf.GetNodeByName(nodeName) |
| 554 | require.NoError(t, err) |
| 555 | lastChild = getChildNodeIndex(n, woc.wf.Status.Nodes, -1) |
| 556 | assert.NotNil(t, lastChild) |
| 557 | |
| 558 | // Last child is still running. processNodeRetries() should return false since |
| 559 | // there should be no retries at this point. |
| 560 | n, _, err = woc.processNodeRetries(ctx, n, retries, &executeTemplateOpts{}) |
| 561 | require.NoError(t, err) |
| 562 | assert.Equal(t, wfv1.NodeRunning, n.Phase) |
| 563 | |
| 564 | // Mark lastChild as successful. |
| 565 | woc.markNodePhase(ctx, lastChild.Name, wfv1.NodeSucceeded) |
| 566 | n, _, err = woc.processNodeRetries(ctx, n, retries, &executeTemplateOpts{}) |
| 567 | require.NoError(t, err) |
| 568 | // The parent node also gets marked as Succeeded. |
| 569 | assert.Equal(t, wfv1.NodeSucceeded, n.Phase) |
| 570 | |
| 571 | // Mark the parent node as running again and the lastChild as failed. |
| 572 | woc.markNodePhase(ctx, n.Name, wfv1.NodeRunning) |
| 573 | woc.markNodePhase(ctx, lastChild.Name, wfv1.NodeFailed) |
| 574 | _, _, err = woc.processNodeRetries(ctx, n, retries, &executeTemplateOpts{}) |
| 575 | require.NoError(t, err) |
| 576 | n, err = woc.wf.GetNodeByName(nodeName) |
| 577 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected