@@ -6,6 +6,7 @@ package websocket_test
6
6
import (
7
7
"context"
8
8
"encoding/json"
9
+ "errors"
9
10
"fmt"
10
11
"io"
11
12
"net"
@@ -20,6 +21,7 @@ import (
20
21
"nhooyr.io/websocket/internal/errd"
21
22
"nhooyr.io/websocket/internal/test/assert"
22
23
"nhooyr.io/websocket/internal/test/wstest"
24
+ "nhooyr.io/websocket/internal/util"
23
25
)
24
26
25
27
var excludedAutobahnCases = []string {
@@ -37,8 +39,7 @@ var autobahnCases = []string{"*"}
37
39
// Used to run individual test cases. autobahnCases runs only those cases matched
38
40
// and not excluded by excludedAutobahnCases. Adding cases here means excludedAutobahnCases
39
41
// is niled.
40
- // TODO:
41
- // var forceAutobahnCases = []string{}
42
+ var onlyAutobahnCases = []string {}
42
43
43
44
func TestAutobahn (t * testing.T ) {
44
45
t .Parallel ()
@@ -54,10 +55,15 @@ func TestAutobahn(t *testing.T) {
54
55
)
55
56
}
56
57
58
+ if len (onlyAutobahnCases ) > 0 {
59
+ excludedAutobahnCases = []string {}
60
+ autobahnCases = onlyAutobahnCases
61
+ }
62
+
57
63
ctx , cancel := context .WithTimeout (context .Background (), time .Hour )
58
64
defer cancel ()
59
65
60
- wstestURL , closeFn , err := wstestServer (ctx )
66
+ wstestURL , closeFn , err := wstestServer (t , ctx )
61
67
assert .Success (t , err )
62
68
defer func () {
63
69
assert .Success (t , closeFn ())
@@ -90,7 +96,7 @@ func TestAutobahn(t *testing.T) {
90
96
assert .Success (t , err )
91
97
c .Close (websocket .StatusNormalClosure , "" )
92
98
93
- checkWSTestIndex (t , "./ci/out/wstestClientReports /index.json" )
99
+ checkWSTestIndex (t , "./ci/out/autobahn-report /index.json" )
94
100
}
95
101
96
102
func waitWS (ctx context.Context , url string ) error {
@@ -109,9 +115,7 @@ func waitWS(ctx context.Context, url string) error {
109
115
return ctx .Err ()
110
116
}
111
117
112
- // TODO: Let docker pick the port and use docker port to find it.
113
- // Does mean we can't use -i but that's fine.
114
- func wstestServer (ctx context.Context ) (url string , closeFn func () error , err error ) {
118
+ func wstestServer (tb testing.TB , ctx context.Context ) (url string , closeFn func () error , err error ) {
115
119
defer errd .Wrap (& err , "failed to start autobahn wstest server" )
116
120
117
121
serverAddr , err := unusedListenAddr ()
@@ -124,7 +128,7 @@ func wstestServer(ctx context.Context) (url string, closeFn func() error, err er
124
128
}
125
129
126
130
url = "ws://" + serverAddr
127
- const outDir = "ci/out/wstestClientReports "
131
+ const outDir = "ci/out/autobahn-report "
128
132
129
133
specFile , err := tempJSONFile (map [string ]interface {}{
130
134
"url" : url ,
@@ -144,9 +148,15 @@ func wstestServer(ctx context.Context) (url string, closeFn func() error, err er
144
148
}()
145
149
146
150
dockerPull := exec .CommandContext (ctx , "docker" , "pull" , "crossbario/autobahn-testsuite" )
147
- // TODO: log to *testing.T
148
- dockerPull .Stdout = os .Stdout
149
- dockerPull .Stderr = os .Stderr
151
+ dockerPull .Stdout = util .WriterFunc (func (p []byte ) (int , error ) {
152
+ tb .Log (string (p ))
153
+ return len (p ), nil
154
+ })
155
+ dockerPull .Stderr = util .WriterFunc (func (p []byte ) (int , error ) {
156
+ tb .Log (string (p ))
157
+ return len (p ), nil
158
+ })
159
+ tb .Log (dockerPull )
150
160
err = dockerPull .Run ()
151
161
if err != nil {
152
162
return "" , nil , fmt .Errorf ("failed to pull docker image: %w" , err )
@@ -169,23 +179,32 @@ func wstestServer(ctx context.Context) (url string, closeFn func() error, err er
169
179
// See https://github.com/crossbario/autobahn-testsuite/blob/058db3a36b7c3a1edf68c282307c6b899ca4857f/autobahntestsuite/autobahntestsuite/wstest.py#L124
170
180
"--webport=0" ,
171
181
)
172
- fmt .Println (strings .Join (args , " " ))
173
182
wstest := exec .CommandContext (ctx , "docker" , args ... )
174
- // TODO: log to *testing.T
175
- wstest .Stdout = os .Stdout
176
- wstest .Stderr = os .Stderr
183
+ wstest .Stdout = util .WriterFunc (func (p []byte ) (int , error ) {
184
+ tb .Log (string (p ))
185
+ return len (p ), nil
186
+ })
187
+ wstest .Stderr = util .WriterFunc (func (p []byte ) (int , error ) {
188
+ tb .Log (string (p ))
189
+ return len (p ), nil
190
+ })
191
+ tb .Log (wstest )
177
192
err = wstest .Start ()
178
193
if err != nil {
179
194
return "" , nil , fmt .Errorf ("failed to start wstest: %w" , err )
180
195
}
181
196
182
- // TODO: kill
183
197
return url , func () error {
184
198
err = wstest .Process .Kill ()
185
199
if err != nil {
186
200
return fmt .Errorf ("failed to kill wstest: %w" , err )
187
201
}
188
- return nil
202
+ err = wstest .Wait ()
203
+ var ee * exec.ExitError
204
+ if errors .As (err , & ee ) && ee .ExitCode () == - 1 {
205
+ return nil
206
+ }
207
+ return err
189
208
}, nil
190
209
}
191
210
0 commit comments