Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

chore: initialise timeout factor next to the declaration #1118

Merged
merged 2 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion e2e/_suites/fleet/ingest_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do the same with any other variable defined in common that needs some initialization, such as this common.AgentVersion.


// check if version is an alias
Expand Down
7 changes: 1 addition & 6 deletions e2e/_suites/helm/helm_charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ var elasticAPMActive = false

var helmManager helm.Manager

// timeoutFactor a multiplier for the max timeout when doing backoff retries.
// It can be overriden by TIMEOUT_FACTOR env var
var timeoutFactor = 2

//nolint:unused
var kubectlClient kubectl.Kubectl

Expand Down Expand Up @@ -80,7 +76,6 @@ func setupSuite() {
helmVersion = shell.GetEnv("HELM_VERSION", helmVersion)
helmChartVersion = shell.GetEnv("HELM_CHART_VERSION", helmChartVersion)
kubernetesVersion = shell.GetEnv("KUBERNETES_VERSION", kubernetesVersion)
timeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", timeoutFactor)

stackVersion = shell.GetEnv("STACK_VERSION", stackVersion)
v, err := utils.GetElasticArtifactVersion(stackVersion)
Expand Down Expand Up @@ -187,7 +182,7 @@ func (ts *HelmChartTestSuite) aResourceWillExposePods(resourceType string) error
return err
}

maxTimeout := time.Duration(timeoutFactor) * time.Minute
maxTimeout := time.Duration(common.TimeoutFactor) * time.Minute

exp := common.GetExponentialBackOff(maxTimeout)
retryCount := 1
Expand Down
11 changes: 3 additions & 8 deletions e2e/_suites/kubernetes-autodiscover/autodiscover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -472,6 +464,9 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
// init logger
config.Init()

defaultEventsWaitTimeout = defaultEventsWaitTimeout * time.Duration(common.TimeoutFactor)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Golang does not warrantee the initialisation order of the init functions, we must move this to the setupSuite, which we are sure will happen after that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some guarantees in order of init executions. In this case I think that common.TimeoutFactor should have been initialized before InitializeTestSuite is called. Wasn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in this case we moved the defaultEventsXXX timeouts to the InitializeTestSuite for that reason, so it's guaranteed that the default value is read from the environment.

defaultDeployWaitTimeout = defaultDeployWaitTimeout * time.Duration(common.TimeoutFactor)

err := cluster.Initialize(suiteContext, "testdata/kind.yml")
if err != nil {
log.WithError(err).Fatal("Failed to initialize cluster")
Expand Down
5 changes: 5 additions & 0 deletions internal/common/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Comment on lines 16 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I see this together. Even better, this should work too, so init() is not needed.

const defaultTimeoutFactor = 3
var TimeoutFactor = shell.GetEnvInteger("TIMEOUT_FACTOR", defaultTimeoutFactor)


// GetExponentialBackOff returns a preconfigured exponential backoff instance
func GetExponentialBackOff(elapsedTime time.Duration) *backoff.ExponentialBackOff {
var (
Expand Down