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

move funcs of expect.go to e2e/common #84410

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion test/e2e/common/pods.go
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io"
"runtime/debug"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -158,6 +159,22 @@ func getRestartDelay(podClient *framework.PodClient, podName string, containerNa
return 0, fmt.Errorf("timeout getting pod restart delay")
}

// expectNoErrorWithRetries checks if an error occurs with the given retry count.
func expectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{}) {
var err error
for i := 0; i < maxRetries; i++ {
err = fn()
if err == nil {
return
}
framework.Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err)
}
if err != nil {
debug.PrintStack()
}
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)
}

var _ = framework.KubeDescribe("Pods", func() {
f := framework.NewDefaultFramework("pods")
var podClient *framework.PodClient
Expand Down Expand Up @@ -526,7 +543,7 @@ var _ = framework.KubeDescribe("Pods", func() {
"FOOSERVICE_PORT_8765_TCP=",
"FOOSERVICE_PORT_8765_TCP_ADDR=",
}
framework.ExpectNoErrorWithRetries(func() error {
expectNoErrorWithRetries(func() error {
return f.MatchContainerOutput(pod, containerName, expectedVars, gomega.ContainSubstring)
}, maxRetries, "Container should have service environment variables set")
})
Expand Down
18 changes: 0 additions & 18 deletions test/e2e/framework/expect.go
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package framework

import (
"runtime/debug"

"github.com/onsi/gomega"
)

Expand Down Expand Up @@ -47,19 +45,3 @@ func ExpectNoError(err error, explain ...interface{}) {
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)
}

// ExpectNoErrorWithRetries checks if an error occurs with the given retry count.
func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interface{}) {
var err error
for i := 0; i < maxRetries; i++ {
err = fn()
if err == nil {
return
}
Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err)
}
if err != nil {
debug.PrintStack()
}
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)
}
1 change: 0 additions & 1 deletion test/e2e/framework/pod/resource.go
Expand Up @@ -42,7 +42,6 @@ import (
)

// TODO: Move to its own subpkg.
// expectNoErrorWithRetries to their own subpackages within framework.
// expectNoError checks if "err" is set, and if so, fails assertion while logging the error.
func expectNoError(err error, explain ...interface{}) {
expectNoErrorWithOffset(1, err, explain...)
Expand Down