Skip to content

Commit

Permalink
changed e2e Tests Retry to iteration count
Browse files Browse the repository at this point in the history
Signed-off-by: jignyasamishra <[email protected]>
  • Loading branch information
jignyasamishra committed Jan 21, 2024
1 parent 0972b2f commit 7383bfd
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions test/e2e/kappcontroller/app_secret_configmap_reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ stringData:
})

logger.Section("check App uses new secret", func() {
retry(t, 10*time.Second, func() error {
retry(t, 10, func() error {
out := kubectl.Run([]string{"get", "configmap/configmap", "-o", "yaml"})

var cm corev1.ConfigMap
Expand Down Expand Up @@ -193,7 +193,7 @@ data:
})

logger.Section("check App uses new configmap", func() {
retry(t, 10*time.Second, func() error {
retry(t, 10, func() error {
out := kubectl.Run([]string{"get", "configmap/configmap", "-o", "yaml"})

var cm corev1.ConfigMap
Expand All @@ -210,17 +210,14 @@ data:
})
}

func retry(t *testing.T, timeout time.Duration, f func() error) {
func retry(t *testing.T, maxRetries int, f func() error) {
var err error
stopTime := time.Now().Add(timeout)
for {
for i := 0; i < maxRetries; i++ {
err = f()
if err == nil {
return
}
if time.Now().After(stopTime) {
t.Fatalf("retry timed out after %s: %v", timeout.String(), err)
}
time.Sleep(1 * time.Second)
}
t.Fatalf("retry failed after %d attempts: %v", maxRetries, err)
}

0 comments on commit 7383bfd

Please sign in to comment.