Skip to content

Commit

Permalink
Random port on test
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-gold-apolicy committed May 4, 2022
1 parent ded0e18 commit c00acdc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,17 +1113,18 @@ func TestWSNoDeadlockOnAuthFailure(t *testing.T) {
}

func TestWSProxyPath(t *testing.T) {
const (
proxyPath = "/proxy1"
proxyPort = "8080"
)

const proxyPath = "/proxy1"
var proxyCalled bool

l, err := net.Listen("tcp", fmt.Sprintf(":%s", proxyPort))
// Listen to a random port
l, err := net.Listen("tcp", ":0")
if err != nil {
t.Fatalf("Error in listen: %v", err)
}
defer l.Close()

proxyPort := l.Addr().(*net.TCPAddr).Port

proxySrv := &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
proxyCalled = r.URL.Path == proxyPath
Expand All @@ -1136,7 +1137,7 @@ func TestWSProxyPath(t *testing.T) {
s := RunServerWithOptions(opt)
defer s.Shutdown()

url := fmt.Sprintf("ws://127.0.0.1:%s", proxyPort)
url := fmt.Sprintf("ws://127.0.0.1:%d", proxyPort)
Connect(url, ProxyPath(proxyPath))

if !proxyCalled {
Expand Down

0 comments on commit c00acdc

Please sign in to comment.