Skip to content

Commit

Permalink
fix: retryStrategy.Limit is now read properly for backoff strategy. F…
Browse files Browse the repository at this point in the history
…ixes argoproj#9170. (argoproj#9213)

* fix: retryStrategy.Limit is now read properly

Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>

* test: add test case for backoff

Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>

* chore: empty commit

Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>

* test: update test case to check for certain amount of retries

Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>

* test: added second case where limit is a string

Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
  • Loading branch information
dpadhiar authored and terrytangyuan committed Aug 2, 2022
1 parent 69b5f1d commit 9c9efa6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
58 changes: 57 additions & 1 deletion test/e2e/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package e2e

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
Expand All @@ -22,7 +23,7 @@ func (s *RetryTestSuite) TestRetryLimit() {
s.Given().
Workflow(`
metadata:
generateName: test-backoff-
generateName: test-retry-limit-
spec:
entrypoint: main
templates:
Expand All @@ -48,6 +49,61 @@ spec:
})
}

func (s *RetryTestSuite) TestRetryBackoff() {
s.Given().
Workflow(`
metadata:
generateName: test-backoff-strategy-
spec:
entrypoint: main
templates:
- name: main
retryStrategy:
limit: '10'
backoff:
duration: 10s
maxDuration: 1m
container:
name: main
image: 'argoproj/argosay:v2'
args: [ exit, "1" ]
`).
When().
SubmitWorkflow().
WaitForWorkflow(time.Minute).
Then().
ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, wfv1.WorkflowPhase("Failed"), status.Phase)
assert.LessOrEqual(t, len(status.Nodes), 10)
})
s.Given().
Workflow(`
metadata:
generateName: test-backoff-strategy-
spec:
entrypoint: main
templates:
- name: main
retryStrategy:
limit: 10
backoff:
duration: 10s
maxDuration: 1m
container:
name: main
image: 'argoproj/argosay:v2'
args: [ exit, "1" ]
`).
When().
SubmitWorkflow().
WaitForWorkflow(time.Minute).
Then().
ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) {
assert.Equal(t, wfv1.WorkflowPhase("Failed"), status.Phase)
assert.LessOrEqual(t, len(status.Nodes), 10)
})
}

func TestRetrySuite(t *testing.T) {
suite.Run(t, new(RetryTestSuite))
}
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func (woc *wfOperationCtx) processNodeRetries(node *wfv1.NodeStatus, retryStrate
}

// See if we have waited past the deadline
if time.Now().Before(waitingDeadline) && retryStrategy.Limit != nil && int32(len(node.Children)) <= retryStrategy.Limit.IntVal {
if time.Now().Before(waitingDeadline) && retryStrategy.Limit != nil && int32(len(node.Children)) <= int32(retryStrategy.Limit.IntValue()) {
woc.requeueAfter(timeToWait)
retryMessage := fmt.Sprintf("Backoff for %s", humanize.Duration(timeToWait))
return woc.markNodePhase(node.Name, node.Phase, retryMessage), false, nil
Expand Down

0 comments on commit 9c9efa6

Please sign in to comment.