...
1
16
17 package service
18
19 import (
20 "context"
21 "time"
22
23 "k8s.io/apimachinery/pkg/util/wait"
24 "k8s.io/kubernetes/test/e2e/framework"
25 e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
26 )
27
28
29 func TestReachableHTTP(ctx context.Context, host string, port int, timeout time.Duration) {
30 TestReachableHTTPWithRetriableErrorCodes(ctx, host, port, []int{}, timeout)
31 }
32
33
34 func TestReachableHTTPWithRetriableErrorCodes(ctx context.Context, host string, port int, retriableErrCodes []int, timeout time.Duration) {
35 pollfn := func(ctx context.Context) (bool, error) {
36 result := e2enetwork.PokeHTTP(host, port, "/echo?msg=hello",
37 &e2enetwork.HTTPPokeParams{
38 BodyContains: "hello",
39 RetriableCodes: retriableErrCodes,
40 })
41 if result.Status == e2enetwork.HTTPSuccess {
42 return true, nil
43 }
44 return false, nil
45 }
46
47 if err := wait.PollUntilContextTimeout(ctx, framework.Poll, timeout, true, pollfn); err != nil {
48 if wait.Interrupted(err) {
49 framework.Failf("Could not reach HTTP service through %v:%v after %v", host, port, timeout)
50 } else {
51 framework.Failf("Failed to reach HTTP service through %v:%v: %v", host, port, err)
52 }
53 }
54 }
55
View as plain text