From d8e83a8189023ccfb62a0ec9d2f8b391853e9310 Mon Sep 17 00:00:00 2001 From: Jignyasa Mishra Date: Mon, 22 Jan 2024 15:41:39 +0530 Subject: [PATCH] changed e2e Tests Retry to iteration count (#1453) Signed-off-by: jignyasamishra --- .../app_secret_configmap_reconcile_test.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/e2e/kappcontroller/app_secret_configmap_reconcile_test.go b/test/e2e/kappcontroller/app_secret_configmap_reconcile_test.go index 5606878c5..63d1ec7e3 100644 --- a/test/e2e/kappcontroller/app_secret_configmap_reconcile_test.go +++ b/test/e2e/kappcontroller/app_secret_configmap_reconcile_test.go @@ -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 @@ -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 @@ -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) }