Skip to content

Commit fdf9cab

Browse files
committed
Deflake TestHTTPProbeProxy
1 parent 3cdfdfc commit fdf9cab

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

pkg/probe/http/http_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ func unsetEnv(key string) func() {
6161

6262
func TestHTTPProbeProxy(t *testing.T) {
6363
res := "welcome to http probe proxy"
64-
localProxy := "http://127.0.0.1:9098/"
64+
65+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66+
fmt.Fprint(w, res)
67+
}))
68+
defer server.Close()
69+
70+
localProxy := server.URL
6571

6672
defer setEnv("http_proxy", localProxy)()
6773
defer setEnv("HTTP_PROXY", localProxy)()
@@ -71,16 +77,6 @@ func TestHTTPProbeProxy(t *testing.T) {
7177
followNonLocalRedirects := true
7278
prober := New(followNonLocalRedirects)
7379

74-
go func() {
75-
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
76-
fmt.Fprint(w, res)
77-
})
78-
err := http.ListenAndServe(":9098", nil)
79-
if err != nil {
80-
t.Errorf("Failed to start foo server: localhost:9098")
81-
}
82-
}()
83-
8480
// take some time to wait server boot
8581
time.Sleep(2 * time.Second)
8682
url, err := url.Parse("http://example.com")

0 commit comments

Comments
 (0)