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 <[email protected]>
1 parent 65dfbdd commit 6ead6aa

20 files changed

+90
-18
lines changed

accept.go

+1
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

+1
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

+50-12
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 "", 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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

dial_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

doc.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
// Package websocket implements the RFC 6455 WebSocket protocol.
@@ -16,7 +17,7 @@
1617
//
1718
// More documentation at https://nhooyr.io/websocket.
1819
//
19-
// Wasm
20+
// # Wasm
2021
//
2122
// The client side supports compiling to Wasm.
2223
// It wraps the WebSocket browser API.
@@ -25,8 +26,8 @@
2526
//
2627
// Some important caveats to be aware of:
2728
//
28-
// - Accept always errors out
29-
// - Conn.Ping is no-op
30-
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
31-
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
29+
// - Accept always errors out
30+
// - Conn.Ping is no-op
31+
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
32+
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
3233
package websocket // import "nhooyr.io/websocket"

export_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

frame_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

internal/test/wstest/echo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func EchoLoop(ctx context.Context, c *websocket.Conn) error {
2121

2222
c.SetReadLimit(1 << 30)
2323

24-
ctx, cancel := context.WithTimeout(ctx, time.Minute)
24+
ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
2525
defer cancel()
2626

2727
b := make([]byte, 32<<10)

internal/test/wstest/pipe.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package wstest

internal/wsjs/wsjs_js.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build js
12
// +build js
23

34
// Package wsjs implements typed access to the browser javascript WebSocket API.

make.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
cd "$(dirname "$0")"
5+
6+
fmt() {
7+
go mod tidy
8+
gofmt -s -w .
9+
goimports -w "-local=$(go list -m)" .
10+
}
11+
12+
if ! command -v wasmbrowsertest >/dev/null; then
13+
go install github.com/agnivade/wasmbrowsertest@latest
14+
fi
15+
16+
fmt
17+
go test -race --timeout=1h ./... "$@"

read.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package websocket

write.go

+1
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)