e2e: use Ginkgo context

All code must use the context from Ginkgo when doing API calls or polling for a
change, otherwise the code would not return immediately when the test gets
aborted.
This commit is contained in:
Patrick Ohly
2022-12-12 10:11:10 +01:00
parent bf1d1dfd0f
commit 2f6c4f5eab
418 changed files with 11489 additions and 11369 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package service
import (
"context"
"time"
"k8s.io/apimachinery/pkg/util/wait"
@@ -25,13 +26,13 @@ import (
)
// TestReachableHTTP tests that the given host serves HTTP on the given port.
func TestReachableHTTP(host string, port int, timeout time.Duration) {
TestReachableHTTPWithRetriableErrorCodes(host, port, []int{}, timeout)
func TestReachableHTTP(ctx context.Context, host string, port int, timeout time.Duration) {
TestReachableHTTPWithRetriableErrorCodes(ctx, host, port, []int{}, timeout)
}
// TestReachableHTTPWithRetriableErrorCodes tests that the given host serves HTTP on the given port with the given retriableErrCodes.
func TestReachableHTTPWithRetriableErrorCodes(host string, port int, retriableErrCodes []int, timeout time.Duration) {
pollfn := func() (bool, error) {
func TestReachableHTTPWithRetriableErrorCodes(ctx context.Context, host string, port int, retriableErrCodes []int, timeout time.Duration) {
pollfn := func(ctx context.Context) (bool, error) {
result := e2enetwork.PokeHTTP(host, port, "/echo?msg=hello",
&e2enetwork.HTTPPokeParams{
BodyContains: "hello",
@@ -43,7 +44,7 @@ func TestReachableHTTPWithRetriableErrorCodes(host string, port int, retriableEr
return false, nil // caller can retry
}
if err := wait.PollImmediate(framework.Poll, timeout, pollfn); err != nil {
if err := wait.PollImmediateWithContext(ctx, framework.Poll, timeout, pollfn); err != nil {
if err == wait.ErrWaitTimeout {
framework.Failf("Could not reach HTTP service through %v:%v after %v", host, port, timeout)
} else {