Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase timeout for all Pods to be eventually ready in E2E tests #2348

Merged
merged 1 commit into from
Jan 7, 2020
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
10 changes: 8 additions & 2 deletions test/e2e/test/elasticsearch/checks_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"reflect"
"sort"
"time"

esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates"
Expand Down Expand Up @@ -227,11 +228,16 @@ func CheckESPassword(b Builder, k *test.K8sClient) test.Step {
}

func CheckExpectedPodsEventuallyReady(b Builder, k *test.K8sClient) test.Step {
// Most tests require less than 5 minutes for all Pods to be running and ready,
// but it occasionally takes longer for various reasons (long pod Pod creation time, long volume binding, etc.).
// We use a longer timeout here to not be impacted too much by those external factors, and only fail
// if things seem to be stuck.
timeout := 15 * time.Minute
return test.Step{
Name: "All expected Pods should eventually be ready",
Test: test.Eventually(func() error {
Test: test.UntilSuccess(func() error {
return checkExpectedPodsReady(b, k)
}),
}, timeout),
}
}

Expand Down
13 changes: 8 additions & 5 deletions test/e2e/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ func ExitOnErr(err error) {
}
}

// Eventually runs the given function until success,
// with a default timeout
// Eventually runs the given function until success with a default timeout.
func Eventually(f func() error) func(*testing.T) {
return UntilSuccess(f, ctx.TestTimeout)
}

// UntilSuccess executes f until it succeeds, or the timeout is reached.
func UntilSuccess(f func() error, timeout time.Duration) func(*testing.T) {
return func(t *testing.T) {
defaultTimeout := Ctx().TestTimeout
fmt.Printf("Retries (%s timeout): ", defaultTimeout)
fmt.Printf("Retries (%s timeout): ", timeout)
err := retry.UntilSuccess(func() error {
fmt.Print(".") // super modern progress bar 2.0!
return f()
}, defaultTimeout, DefaultRetryDelay)
}, timeout, DefaultRetryDelay)
fmt.Println()
require.NoError(t, err)
}
Expand Down