1
+ //go:build !js
1
2
// +build !js
2
3
3
4
package websocket_test
@@ -33,6 +34,12 @@ var excludedAutobahnCases = []string{
33
34
34
35
var autobahnCases = []string {"*" }
35
36
37
+ // Used to run individual test cases. autobahnCases runs only those cases matched
38
+ // and not excluded by excludedAutobahnCases. Adding cases here means excludedAutobahnCases
39
+ // is niled.
40
+ // TODO:
41
+ var forceAutobahnCases = []string {}
42
+
36
43
func TestAutobahn (t * testing.T ) {
37
44
t .Parallel ()
38
45
@@ -43,16 +50,18 @@ func TestAutobahn(t *testing.T) {
43
50
if os .Getenv ("AUTOBAHN" ) == "fast" {
44
51
// These are the slow tests.
45
52
excludedAutobahnCases = append (excludedAutobahnCases ,
46
- "9.*" , "13 .*" , "12 .*" ,
53
+ "9.*" , "12 .*" , "13 .*" ,
47
54
)
48
55
}
49
56
50
- ctx , cancel := context .WithTimeout (context .Background (), time .Minute * 15 )
57
+ ctx , cancel := context .WithTimeout (context .Background (), time .Hour )
51
58
defer cancel ()
52
59
53
- wstestURL , closeFn , err := wstestClientServer (ctx )
60
+ wstestURL , closeFn , err := wstestServer (ctx )
54
61
assert .Success (t , err )
55
- defer closeFn ()
62
+ defer func () {
63
+ assert .Success (t , closeFn ())
64
+ }()
56
65
57
66
err = waitWS (ctx , wstestURL )
58
67
assert .Success (t , err )
@@ -100,44 +109,73 @@ func waitWS(ctx context.Context, url string) error {
100
109
return ctx .Err ()
101
110
}
102
111
103
- func wstestClientServer (ctx context.Context ) (url string , closeFn func (), err error ) {
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 ) {
104
115
serverAddr , err := unusedListenAddr ()
105
116
if err != nil {
106
117
return "" , nil , err
107
118
}
119
+ _ , serverPort , err := net .SplitHostPort (serverAddr )
120
+ if err != nil {
121
+ return "" , nil , err
122
+ }
108
123
109
124
url = "ws://" + serverAddr
125
+ const outDir = "ci/out/wstestClientReports"
110
126
111
127
specFile , err := tempJSONFile (map [string ]interface {}{
112
128
"url" : url ,
113
- "outdir" : "ci/out/wstestClientReports" ,
129
+ "outdir" : outDir ,
114
130
"cases" : autobahnCases ,
115
131
"exclude-cases" : excludedAutobahnCases ,
116
132
})
117
133
if err != nil {
118
134
return "" , nil , fmt .Errorf ("failed to write spec: %w" , err )
119
135
}
120
136
121
- ctx , cancel := context .WithTimeout (context . Background () , time .Minute * 15 )
137
+ ctx , cancel := context .WithTimeout (ctx , time .Hour )
122
138
defer func () {
123
139
if err != nil {
124
140
cancel ()
125
141
}
126
142
}()
127
143
128
- args := []string {"--mode" , "fuzzingserver" , "--spec" , specFile ,
144
+ wd , err := os .Getwd ()
145
+ if err != nil {
146
+ return "" , nil , err
147
+ }
148
+
149
+ var args []string
150
+ args = append (args , "run" , "-i" , "--rm" ,
151
+ "-v" , fmt .Sprintf ("%s:%[1]s" , specFile ),
152
+ "-v" , fmt .Sprintf ("%s/ci:/ci" , wd ),
153
+ fmt .Sprintf ("-p=%s:%s" , serverAddr , serverPort ),
154
+ "crossbario/autobahn-testsuite" ,
155
+ )
156
+ args = append (args , "wstest" , "--mode" , "fuzzingserver" , "--spec" , specFile ,
129
157
// Disables some server that runs as part of fuzzingserver mode.
130
158
// See https://github.com/crossbario/autobahn-testsuite/blob/058db3a36b7c3a1edf68c282307c6b899ca4857f/autobahntestsuite/autobahntestsuite/wstest.py#L124
131
159
"--webport=0" ,
132
- }
133
- wstest := exec .CommandContext (ctx , "wstest" , args ... )
160
+ )
161
+ fmt .Println (strings .Join (args , " " ))
162
+ // TODO: pull image in advance
163
+ wstest := exec .CommandContext (ctx , "docker" , args ... )
164
+ // TODO: log to *testing.T
165
+ wstest .Stdout = os .Stdout
166
+ wstest .Stderr = os .Stderr
134
167
err = wstest .Start ()
135
168
if err != nil {
136
169
return "" , nil , fmt .Errorf ("failed to start wstest: %w" , err )
137
170
}
138
171
139
- return url , func () {
140
- wstest .Process .Kill ()
172
+ // TODO: kill
173
+ return url , func () error {
174
+ err = wstest .Process .Kill ()
175
+ if err != nil {
176
+ return fmt .Errorf ("failed to kill wstest: %w" , err )
177
+ }
178
+ return nil
141
179
}, nil
142
180
}
143
181
0 commit comments