From eb30ca2c4a56cdca18087254b89d360d3db1b8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 4 May 2021 10:53:20 +0200 Subject: [PATCH] chore: initialise timeout factor on its own package --- e2e/_suites/fleet/ingest_manager_test.go | 1 - .../kubernetes-autodiscover/autodiscover_test.go | 11 +++-------- internal/common/retry.go | 5 +++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/e2e/_suites/fleet/ingest_manager_test.go b/e2e/_suites/fleet/ingest_manager_test.go index c2366e2785..7634467d4f 100644 --- a/e2e/_suites/fleet/ingest_manager_test.go +++ b/e2e/_suites/fleet/ingest_manager_test.go @@ -48,7 +48,6 @@ func setUpSuite() { } common.AgentVersionBase = v - common.TimeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", common.TimeoutFactor) common.AgentVersion = shell.GetEnv("BEAT_VERSION", common.AgentVersionBase) // check if version is an alias diff --git a/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go b/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go index 667db8be18..9492ff7c14 100644 --- a/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go +++ b/e2e/_suites/kubernetes-autodiscover/autodiscover_test.go @@ -37,14 +37,6 @@ const defaultBeatVersion = "8.0.0-SNAPSHOT" var defaultEventsWaitTimeout = 60 * time.Second var defaultDeployWaitTimeout = 60 * time.Second -func init() { - // initialise timeout factor - common.TimeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", common.TimeoutFactor) - - defaultEventsWaitTimeout = defaultEventsWaitTimeout * time.Duration(common.TimeoutFactor) - defaultDeployWaitTimeout = defaultDeployWaitTimeout * time.Duration(common.TimeoutFactor) -} - type podsManager struct { kubectl kubernetes.Control ctx context.Context @@ -472,6 +464,9 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) { // init logger config.Init() + defaultEventsWaitTimeout = defaultEventsWaitTimeout * time.Duration(common.TimeoutFactor) + defaultDeployWaitTimeout = defaultDeployWaitTimeout * time.Duration(common.TimeoutFactor) + err := cluster.Initialize(suiteContext, "testdata/kind.yml") if err != nil { log.WithError(err).Fatal("Failed to initialize cluster") diff --git a/internal/common/retry.go b/internal/common/retry.go index fa38cb95a1..2c221bd61f 100644 --- a/internal/common/retry.go +++ b/internal/common/retry.go @@ -8,12 +8,17 @@ import ( "time" backoff "github.com/cenkalti/backoff/v4" + "github.com/elastic/e2e-testing/internal/shell" ) // TimeoutFactor a multiplier for the max timeout when doing backoff retries. // It can be overriden by TIMEOUT_FACTOR env var var TimeoutFactor = 3 +func init() { + TimeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", TimeoutFactor) +} + // GetExponentialBackOff returns a preconfigured exponential backoff instance func GetExponentialBackOff(elapsedTime time.Duration) *backoff.ExponentialBackOff { var (