From ded0e1833fd12273ff114054071029746d481a6a Mon Sep 17 00:00:00 2001 From: Ido Gold Date: Tue, 3 May 2022 17:51:25 +0300 Subject: [PATCH] Fix test --- ws_test.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) 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") } }