diff --git a/ws_test.go b/ws_test.go index 4175c2873..5abf9dd83 100644 --- a/ws_test.go +++ b/ws_test.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "math/rand" + "net" "net/http" "reflect" "runtime" @@ -1113,19 +1114,23 @@ func TestWSNoDeadlockOnAuthFailure(t *testing.T) { func TestWSProxyPath(t *testing.T) { const ( - proxyPath = "proxy1" + proxyPath = "/proxy1" proxyPort = "8080" ) var proxyCalled bool - http.HandleFunc("/"+proxyPath, func(w http.ResponseWriter, r *http.Request) { - proxyCalled = true - }) - - httpServer := &http.Server{Addr: ":" + proxyPort} - defer httpServer.Shutdown(context.Background()) - go httpServer.ListenAndServe() + l, err := net.Listen("tcp", fmt.Sprintf(":%s", proxyPort)) + if err != nil { + t.Fatalf("Error in listen: %v", err) + } + proxySrv := &http.Server{ + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + proxyCalled = r.URL.Path == proxyPath + }), + } + defer proxySrv.Shutdown(context.Background()) + go proxySrv.Serve(l) opt := testWSGetDefaultOptions(t, false) s := RunServerWithOptions(opt) @@ -1135,6 +1140,6 @@ func TestWSProxyPath(t *testing.T) { Connect(url, ProxyPath(proxyPath)) if !proxyCalled { - t.Fatal("Proxy didnt called") + t.Fatal("Proxy haven't been called") } }