mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-26 19:35:10 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user