From 0b10870e64a69a295eeded1b4cda641ffef0adc1 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Tue, 26 Sep 2023 09:56:35 +0200 Subject: [PATCH] extend test retries via flags --- .../workflows/pull-with-lifecycle-manager.yaml | 2 +- e2e/setup/setup_test.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-with-lifecycle-manager.yaml b/.github/workflows/pull-with-lifecycle-manager.yaml index 0efeba9a..6ac9f227 100644 --- a/.github/workflows/pull-with-lifecycle-manager.yaml +++ b/.github/workflows/pull-with-lifecycle-manager.yaml @@ -161,7 +161,7 @@ jobs: # Waits for NATS-manager image to be updated and NATS CR readiness. run: | export MANAGER_IMAGE=${DOCKER_IMAGE} - make e2e-setup + go test -v ./e2e/setup/setup_test.go --tags=e2e --interval=3 --attempts=120 - name: Run NATS bench run: | diff --git a/e2e/setup/setup_test.go b/e2e/setup/setup_test.go index 4daab0e0..fcdbc491 100644 --- a/e2e/setup/setup_test.go +++ b/e2e/setup/setup_test.go @@ -9,6 +9,7 @@ package setup_test import ( "context" + "flag" "fmt" "os" "reflect" @@ -33,10 +34,14 @@ import ( // Constants for retries. const ( - interval = 2 * time.Second - attempts = 60 + defaultInterval = 2 * time.Second + defaultAttempts = 60 ) +// variables for retries. +var interval int +var attempts int + // clientSet is what is used to access K8s build-in resources like Pods, Namespaces and so on. var clientSet *kubernetes.Clientset //nolint:gochecknoglobals // This will only be accessible in e2e tests. @@ -45,6 +50,11 @@ var k8sClient client.Client //nolint:gochecknoglobals // This will only be acces var logger *zap.Logger +func init() { + flag.Int(&interval, "interval", defaultInterval, "the interval for test retries") + flag.Int(&attempts, "attempts", defaultAttempts, "the number of attempts for test retries") +} + // TestMain runs before all the other test functions. It sets up all the resources that are shared between the different // test functions. It will then run the tests and finally shuts everything down. func TestMain(m *testing.M) { @@ -54,6 +64,9 @@ func TestMain(m *testing.M) { logger.Fatal(err.Error()) } + // Parse arguments that are passed to the tests. + flag.Parse() + clientSet, k8sClient, err = GetK8sClients() if err != nil { logger.Fatal(err.Error())