Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-gold-apolicy committed May 3, 2022
1 parent e0099bf commit ded0e18
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"math/rand"
"net"
"net/http"
"reflect"
"runtime"
Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
}

0 comments on commit ded0e18

Please sign in to comment.