Commit 382f5c83 authored by Tim Hockin's avatar Tim Hockin

Retool HTTP and UDP e2e utils

This is a prefactoring for followup changes that need to use very similar but subtly different test. Now it is more generic, though it pushes a little logic up the stack. That makes sense to me.
parent 19e333b5
...@@ -876,9 +876,19 @@ func (j *ServiceTestJig) TestReachableHTTP(host string, port int, timeout time.D ...@@ -876,9 +876,19 @@ func (j *ServiceTestJig) TestReachableHTTP(host string, port int, timeout time.D
} }
func (j *ServiceTestJig) TestReachableHTTPWithRetriableErrorCodes(host string, port int, retriableErrCodes []int, timeout time.Duration) { func (j *ServiceTestJig) TestReachableHTTPWithRetriableErrorCodes(host string, port int, retriableErrCodes []int, timeout time.Duration) {
if err := wait.PollImmediate(Poll, timeout, func() (bool, error) { pollfn := func() (bool, error) {
return TestReachableHTTPWithRetriableErrorCodes(host, port, "/echo?msg=hello", "hello", retriableErrCodes) result := PokeHTTP(host, port, "/echo?msg=hello",
}); err != nil { &HTTPPokeParams{
BodyContains: "hello",
RetriableCodes: retriableErrCodes,
})
if result.Status == HTTPSuccess {
return true, nil
}
return false, nil // caller can retry
}
if err := wait.PollImmediate(Poll, timeout, pollfn); err != nil {
if err == wait.ErrWaitTimeout { if err == wait.ErrWaitTimeout {
Failf("Could not reach HTTP service through %v:%v after %v", host, port, timeout) Failf("Could not reach HTTP service through %v:%v after %v", host, port, timeout)
} else { } else {
...@@ -888,36 +898,60 @@ func (j *ServiceTestJig) TestReachableHTTPWithRetriableErrorCodes(host string, p ...@@ -888,36 +898,60 @@ func (j *ServiceTestJig) TestReachableHTTPWithRetriableErrorCodes(host string, p
} }
func (j *ServiceTestJig) TestNotReachableHTTP(host string, port int, timeout time.Duration) { func (j *ServiceTestJig) TestNotReachableHTTP(host string, port int, timeout time.Duration) {
if err := wait.PollImmediate(Poll, timeout, func() (bool, error) { return TestNotReachableHTTP(host, port) }); err != nil { pollfn := func() (bool, error) {
Failf("Could still reach HTTP service through %v:%v after %v: %v", host, port, timeout, err) result := PokeHTTP(host, port, "/", nil)
if result.Code == 0 {
return true, nil
}
return false, nil // caller can retry
}
if err := wait.PollImmediate(Poll, timeout, pollfn); err != nil {
Failf("HTTP service %v:%v reachable after %v: %v", host, port, timeout, err)
} }
} }
func (j *ServiceTestJig) TestReachableUDP(host string, port int, timeout time.Duration) { func (j *ServiceTestJig) TestReachableUDP(host string, port int, timeout time.Duration) {
if err := wait.PollImmediate(Poll, timeout, func() (bool, error) { return TestReachableUDP(host, port, "echo hello", "hello") }); err != nil { pollfn := func() (bool, error) {
result := PokeUDP(host, port, "echo hello", &UDPPokeParams{
Timeout: 3 * time.Second,
Response: "hello",
})
if result.Status == UDPSuccess {
return true, nil
}
return false, nil // caller can retry
}
if err := wait.PollImmediate(Poll, timeout, pollfn); err != nil {
Failf("Could not reach UDP service through %v:%v after %v: %v", host, port, timeout, err) Failf("Could not reach UDP service through %v:%v after %v: %v", host, port, timeout, err)
} }
} }
func (j *ServiceTestJig) TestNotReachableUDP(host string, port int, timeout time.Duration) { func (j *ServiceTestJig) TestNotReachableUDP(host string, port int, timeout time.Duration) {
if err := wait.PollImmediate(Poll, timeout, func() (bool, error) { return TestNotReachableUDP(host, port, "echo hello") }); err != nil { pollfn := func() (bool, error) {
Failf("Could still reach UDP service through %v:%v after %v: %v", host, port, timeout, err) result := PokeUDP(host, port, "echo hello", &UDPPokeParams{Timeout: 3 * time.Second})
if result.Status != UDPSuccess && result.Status != UDPError {
return true, nil
}
return false, nil // caller can retry
}
if err := wait.PollImmediate(Poll, timeout, pollfn); err != nil {
Failf("UDP service %v:%v reachable after %v: %v", host, port, timeout, err)
} }
} }
func (j *ServiceTestJig) GetHTTPContent(host string, port int, timeout time.Duration, url string) bytes.Buffer { func (j *ServiceTestJig) GetHTTPContent(host string, port int, timeout time.Duration, url string) bytes.Buffer {
var body bytes.Buffer var body bytes.Buffer
var err error
if pollErr := wait.PollImmediate(Poll, timeout, func() (bool, error) { if pollErr := wait.PollImmediate(Poll, timeout, func() (bool, error) {
var result bool result := PokeHTTP(host, port, url, nil)
result, err = TestReachableHTTPWithContent(host, port, url, "", &body) if result.Status == HTTPSuccess {
if err != nil { body.Write(result.Body)
Logf("Error hitting %v:%v%v, retrying: %v", host, port, url, err) return true, nil
return false, nil
} }
return result, nil return false, nil
}); pollErr != nil { }); pollErr != nil {
Failf("Could not reach HTTP service through %v:%v%v after %v: %v", host, port, url, timeout, err) Failf("Could not reach HTTP service through %v:%v%v after %v: %v", host, port, url, timeout, pollErr)
} }
return body return body
} }
...@@ -930,7 +964,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err ...@@ -930,7 +964,7 @@ func testHTTPHealthCheckNodePort(ip string, port int, request string) (bool, err
return false, fmt.Errorf("Invalid input ip or port") return false, fmt.Errorf("Invalid input ip or port")
} }
Logf("Testing HTTP health check on %v", url) Logf("Testing HTTP health check on %v", url)
resp, err := httpGetNoConnectionPool(url) resp, err := httpGetNoConnectionPoolTimeout(url, 5*time.Second)
if err != nil { if err != nil {
Logf("Got error testing for reachability of %s: %v", url, err) Logf("Got error testing for reachability of %s: %v", url, err)
return false, err return false, err
......
...@@ -188,11 +188,11 @@ var _ = SIGDescribe("Firewall rule", func() { ...@@ -188,11 +188,11 @@ var _ = SIGDescribe("Firewall rule", func() {
}) })
func assertNotReachableHTTPTimeout(ip string, port int, timeout time.Duration) { func assertNotReachableHTTPTimeout(ip string, port int, timeout time.Duration) {
unreachable, err := framework.TestNotReachableHTTPTimeout(ip, port, timeout) result := framework.PokeHTTP(ip, port, "/", &framework.HTTPPokeParams{Timeout: timeout})
if err != nil { if result.Status == framework.HTTPError {
framework.Failf("Unexpected error checking for reachability of %s:%d: %v", ip, port, err) framework.Failf("Unexpected error checking for reachability of %s:%d: %v", ip, port, result.Error)
} }
if !unreachable { if result.Code != 0 {
framework.Failf("Was unexpectedly able to reach %s:%d", ip, port) framework.Failf("Was unexpectedly able to reach %s:%d", ip, port)
} }
} }
...@@ -2063,14 +2063,18 @@ var _ = SIGDescribe("ESIPP [Slow] [DisabledForLargeClusters]", func() { ...@@ -2063,14 +2063,18 @@ var _ = SIGDescribe("ESIPP [Slow] [DisabledForLargeClusters]", func() {
for nodeName, nodeIPs := range endpointNodeMap { for nodeName, nodeIPs := range endpointNodeMap {
By(fmt.Sprintf("checking kube-proxy health check fails on node with endpoint (%s), public IP %s", nodeName, nodeIPs[0])) By(fmt.Sprintf("checking kube-proxy health check fails on node with endpoint (%s), public IP %s", nodeName, nodeIPs[0]))
var body bytes.Buffer var body bytes.Buffer
var result bool pollfn := func() (bool, error) {
var err error result := framework.PokeHTTP(nodeIPs[0], healthCheckNodePort, "/healthz", nil)
if pollErr := wait.PollImmediate(framework.Poll, framework.ServiceTestTimeout, func() (bool, error) { if result.Code == 0 {
result, err = framework.TestReachableHTTPWithContent(nodeIPs[0], healthCheckNodePort, "/healthz", "", &body) return true, nil
return !result, nil }
}); pollErr != nil { body.Reset()
framework.Failf("Kube-proxy still exposing health check on node %v:%v, after ESIPP was turned off. Last err %v, last body %v", body.Write(result.Body)
nodeName, healthCheckNodePort, err, body.String()) return false, nil
}
if pollErr := wait.PollImmediate(framework.Poll, framework.ServiceTestTimeout, pollfn); pollErr != nil {
framework.Failf("Kube-proxy still exposing health check on node %v:%v, after ESIPP was turned off. body %s",
nodeName, healthCheckNodePort, body.String())
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment