10000 autobahn_test: Use docker to avoid issues with python2 EOL · coder/websocket@6ead6aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ead6aa

Browse files
nhooyrparalin
andcommitted
autobahn_test: Use docker to avoid issues with python2 EOL
Also ran gofmt on everything. Thanks again @paralin. #334 Co-authored-by: Christian Stewart <christian@paral.in>
1 parent 65dfbdd commit 6ead6aa

20 files changed

+90
-18
lines changed

accept.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

accept_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

autobahn_test.go

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket_test
@@ -33,6 +34,12 @@ var excludedAutobahnCases = []string{
3334

3435
var autobahnCases = []string{"*"}
3536

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+
3643
func TestAutobahn(t *testing.T) {
3744
t.Parallel()
3845

@@ -43,16 +50,18 @@ func TestAutobahn(t *testing.T) {
4350
if os.Getenv("AUTOBAHN") == "fast" {
4451
// These are the slow tests.
4552
excludedAutobahnCases = append(excludedAutobahnCases,
46-
"9.*", "13.*", "12.*",
53+
"9.*", "12.*", "13.*",
4754
)
4855
}
4956

50-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
57+
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
5158
defer cancel()
5259

53-
wstestURL, closeFn, err := wstestClientServer(ctx)
60+
wstestURL, closeFn, err := wstestServer(ctx)
5461
assert.Success(t, err)
55-
defer closeFn()
62+
defer func() {
63+
assert.Success(t, closeFn())
64+
}()
5665

5766
err = waitWS(ctx, wstestURL)
5867
assert.Success(t, err)
@@ -100,44 +109,73 @@ func waitWS(ctx context.Context, url string) error {
100109
return ctx.Err()
101110
}
102111

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) {
104115
serverAddr, err := unusedListenAddr()
105116
if err != nil {
106117
return "", nil, err
107118
}
119+
_, serverPort, err := net.SplitHostPort(serverAddr)
120+
if err != nil {
121+
return "", nil, err
122+
}
108123

109124
url = "ws://" + serverAddr
125+
const outDir = "ci/out/wstestClientReports"
110126

111127
specFile, err := tempJSONFile(map[string]interface{}{
112128
"url": url,
113-
"outdir": "ci/out/wstestClientReports",
129+
"outdir": outDir,
114130
"cases": autobahnCases,
115131
"exclude-cases": excludedAutobahnCases,
116132
})
117133
if err != nil {
118134
return "", nil, fmt.Errorf("failed to write spec: %w", err)
119135
}
120136

121-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
137+
ctx, cancel := context.WithTimeout(ctx, time.Hour)
122138
defer func() {
123139
if err != nil {
124140
cancel()
125141
}
126142
}()
127143

128-
args := []string{"--mode", "fuzzingserver", "--spec", specFile,
144+
wd, err := os.Getwd()
145+
if err != nil {
146+
return " 10000 ", 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,
129157
// Disables some server that runs as part of fuzzingserver mode.
130158
// See https://github.com/crossbario/autobahn-testsuite/blob/058db3a36b7c3a1edf68c282307c6b899ca4857f/autobahntestsuite/autobahntestsuite/wstest.py#L124
131159
"--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
134167
err = wstest.Start()
135168
if err != nil {
136169
return "", nil, fmt.Errorf("failed to start wstest: %w", err)
137170
}
138171

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
141179
}, nil
142180
}
143181

close.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

close_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

compress.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

compress_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

conn_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket_test

dial.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

0 commit comments

Comments
 (0)
0