6
6
"fmt"
7
7
"io"
8
8
"io/ioutil"
9
+ "net"
9
10
"net/http"
10
11
"net/http/cookiejar"
11
12
"net/http/httptest"
@@ -781,12 +782,28 @@ func discardLoop(ctx context.Context, c *websocket.Conn) {
781
782
}
782
783
}
783
784
785
+ func unusedListenAddr () (string , error ) {
786
+ l , err := net .Listen ("tcp" , "localhost:0" )
787
+ if err != nil {
788
+ return "" , err
789
+ }
790
+ l .Close ()
791
+ return l .Addr ().String (), nil
792
+ }
793
+
784
794
// https://github.com/crossbario/autobahn-python/blob/master/wstest/testee_client_aio.py
785
795
func TestAutobahnClient (t * testing.T ) {
786
796
t .Parallel ()
787
797
798
+ serverAddr , err := unusedListenAddr ()
799
+ if err != nil {
800
+ t .Fatalf ("failed to get unused listen addr for wstest: %v" , err )
801
+ }
802
+
803
+ wsServerURL := "ws://" + serverAddr
804
+
788
805
spec := map [string ]interface {}{
789
- "url" : "ws://localhost:9001" ,
806
+ "url" : wsServerURL ,
790
807
"outdir" : "ci/out/wstestClientReports" ,
791
808
"cases" : []string {"*" },
792
809
// See TestAutobahnServer for the reasons why we exclude these.
@@ -814,9 +831,10 @@ func TestAutobahnClient(t *testing.T) {
814
831
ctx , cancel := context .WithTimeout (ctx , time .Minute * 10 )
815
832
defer cancel ()
816
833
817
- args := []string {"--mode" , "fuzzingserver" , "--spec" , specFile .Name ()}
818
- if os .Getenv ("CI" ) == "" {
819
- args = append ([]string {"--debug" }, args ... )
834
+ args := []string {"--mode" , "fuzzingserver" , "--spec" , specFile .Name (),
835
+ // Disables some server that runs as part of fuzzingserver mode.
836
+ // See https://github.com/crossbario/autobahn-testsuite/blob/058db3a36b7c3a1edf68c282307c6b899ca4857f/autobahntestsuite/autobahntestsuite/wstest.py#L124
837
+ "--webport=0" ,
820
838
}
821
839
wstest := exec .CommandContext (ctx , "wstest" , args ... )
822
840
err = wstest .Start ()
@@ -835,9 +853,9 @@ func TestAutobahnClient(t *testing.T) {
835
853
836
854
var cases int
837
855
func () {
838
- c , _ , err := websocket .Dial (ctx , "ws://localhost:9001 /getCaseCount" , websocket.DialOptions {})
856
+ c , _ , err := websocket .Dial (ctx , wsServerURL + " /getCaseCount" , websocket.DialOptions {})
839
857
if err != nil {
840
- t .Fatalf ( "failed to dial: %v" , err )
858
+ t .Fatal ( err )
841
859
}
842
860
defer c .Close (websocket .StatusInternalError , "" )
843
861
@@ -862,17 +880,17 @@ func TestAutobahnClient(t *testing.T) {
862
880
ctx , cancel := context .WithTimeout (ctx , time .Second * 45 )
863
881
defer cancel ()
864
882
865
- c , _ , err := websocket .Dial (ctx , fmt .Sprintf ("ws://localhost:9001 /runCase?case=%v&agent=main" , i ), websocket.DialOptions {})
883
+ c , _ , err := websocket .Dial (ctx , fmt .Sprintf (wsServerURL + " /runCase?case=%v&agent=main" , i ), websocket.DialOptions {})
866
884
if err != nil {
867
- t .Fatalf ( "failed to dial: %v" , err )
885
+ t .Fatal ( err )
868
886
}
869
887
echoLoop (ctx , c )
870
888
}()
871
889
}
872
890
873
- c , _ , err := websocket .Dial (ctx , fmt .Sprintf ("ws://localhost:9001 /updateReports?agent=main" ), websocket.DialOptions {})
891
+ c , _ , err := websocket .Dial (ctx , fmt .Sprintf (wsServerURL + " /updateReports?agent=main" ), websocket.DialOptions {})
874
892
if err != nil {
875
- t .Fatalf ( "failed to dial: %v" , err )
893
+ t .Fatal ( err )
876
894
}
877
895
c .Close (websocket .StatusNormalClosure , "" )
878
896
@@ -944,7 +962,7 @@ func benchConn(b *testing.B, echo, stream bool, size int) {
944
962
945
963
c , _ , err := websocket .Dial (ctx , wsURL , websocket.DialOptions {})
946
964
if err != nil {
947
- b .Fatalf ( "failed to dial: %v" , err )
965
+ b .Fatal ( err )
948
966
}
949
967
defer c .Close (websocket .StatusInternalError , "" )
950
968
0 commit comments