mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-03 18:27:49 +00:00
Deflake TestHTTPProbeProxy
This commit is contained in:
@@ -61,7 +61,13 @@ func unsetEnv(key string) func() {
|
|||||||
|
|
||||||
func TestHTTPProbeProxy(t *testing.T) {
|
func TestHTTPProbeProxy(t *testing.T) {
|
||||||
res := "welcome to http probe proxy"
|
res := "welcome to http probe proxy"
|
||||||
localProxy := "http://127.0.0.1:9098/"
|
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprint(w, res)
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
localProxy := server.URL
|
||||||
|
|
||||||
defer setEnv("http_proxy", localProxy)()
|
defer setEnv("http_proxy", localProxy)()
|
||||||
defer setEnv("HTTP_PROXY", localProxy)()
|
defer setEnv("HTTP_PROXY", localProxy)()
|
||||||
@@ -71,16 +77,6 @@ func TestHTTPProbeProxy(t *testing.T) {
|
|||||||
followNonLocalRedirects := true
|
followNonLocalRedirects := true
|
||||||
prober := New(followNonLocalRedirects)
|
prober := New(followNonLocalRedirects)
|
||||||
|
|
||||||
go func() {
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
fmt.Fprint(w, res)
|
|
||||||
})
|
|
||||||
err := http.ListenAndServe(":9098", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Failed to start foo server: localhost:9098")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// take some time to wait server boot
|
// take some time to wait server boot
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
url, err := url.Parse("http://example.com")
|
url, err := url.Parse("http://example.com")
|
||||||
|
Reference in New Issue
Block a user