Skip to content

Commit

Permalink
autobahn_test: Use docker to avoid issues with python2 EOL
Browse files Browse the repository at this point in the history
Also ran gofmt on everything. Thanks again @paralin. #334

Co-authored-by: Christian Stewart <christian@paral.in>
  • Loading branch information
nhooyr and paralin committed Oct 10, 2023
1 parent 65dfbdd commit 6ead6aa
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 18 deletions.
1 change: 1 addition & 0 deletions accept.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions accept_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
62 changes: 50 additions & 12 deletions autobahn_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

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

var autobahnCases = []string{"*"}

// Used to run individual test cases. autobahnCases runs only those cases matched
// and not excluded by excludedAutobahnCases. Adding cases here means excludedAutobahnCases
// is niled.
// TODO:
var forceAutobahnCases = []string{}

func TestAutobahn(t *testing.T) {
t.Parallel()

Expand All @@ -43,16 +50,18 @@ func TestAutobahn(t *testing.T) {
if os.Getenv("AUTOBAHN") == "fast" {
// These are the slow tests.
excludedAutobahnCases = append(excludedAutobahnCases,
"9.*", "13.*", "12.*",
"9.*", "12.*", "13.*",
)
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
defer cancel()

wstestURL, closeFn, err := wstestClientServer(ctx)
wstestURL, closeFn, err := wstestServer(ctx)
assert.Success(t, err)
defer closeFn()
defer func() {
assert.Success(t, closeFn())
}()

err = waitWS(ctx, wstestURL)
assert.Success(t, err)
Expand Down Expand Up @@ -100,44 +109,73 @@ func waitWS(ctx context.Context, url string) error {
return ctx.Err()
}

func wstestClientServer(ctx context.Context) (url string, closeFn func(), err error) {
// TODO: Let docker pick the port and use docker port to find it.
// Does mean we can't use -i but that's fine.
func wstestServer(ctx context.Context) (url string, closeFn func() error, err error) {
serverAddr, err := unusedListenAddr()
if err != nil {
return "", nil, err
}
_, serverPort, err := net.SplitHostPort(serverAddr)
if err != nil {
return "", nil, err
}

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

specFile, err := tempJSONFile(map[string]interface{}{
"url": url,
"outdir": "ci/out/wstestClientReports",
"outdir": outDir,
"cases": autobahnCases,
"exclude-cases": excludedAutobahnCases,
})
if err != nil {
return "", nil, fmt.Errorf("failed to write spec: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
ctx, cancel := context.WithTimeout(ctx, time.Hour)
defer func() {
if err != nil {
cancel()
}
}()

args := []string{"--mode", "fuzzingserver", "--spec", specFile,
wd, err := os.Getwd()
if err != nil {
return "", nil, err
}

var args []string
args = append(args, "run", "-i", "--rm",
"-v", fmt.Sprintf("%s:%[1]s", specFile),
"-v", fmt.Sprintf("%s/ci:/ci", wd),
fmt.Sprintf("-p=%s:%s", serverAddr, serverPort),
"crossbario/autobahn-testsuite",
)
args = append(args, "wstest", "--mode", "fuzzingserver", "--spec", specFile,
// Disables some server that runs as part of fuzzingserver mode.
// See https://github.com/crossbario/autobahn-testsuite/blob/058db3a36b7c3a1edf68c282307c6b899ca4857f/autobahntestsuite/autobahntestsuite/wstest.py#L124
"--webport=0",
}
wstest := exec.CommandContext(ctx, "wstest", args...)
)
fmt.Println(strings.Join(args, " "))
// TODO: pull image in advance
wstest := exec.CommandContext(ctx, "docker", args...)
// TODO: log to *testing.T
wstest.Stdout = os.Stdout
wstest.Stderr = os.Stderr
err = wstest.Start()
if err != nil {
return "", nil, fmt.Errorf("failed to start wstest: %w", err)
}

return url, func() {
wstest.Process.Kill()
// TODO: kill
return url, func() error {
err = wstest.Process.Kill()
if err != nil {
return fmt.Errorf("failed to kill wstest: %w", err)
}
return nil
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions close.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions close_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions compress.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions compress_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions conn.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket_test
Expand Down
1 change: 1 addition & 0 deletions dial.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions dial_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
11 changes: 6 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

// Package websocket implements the RFC 6455 WebSocket protocol.
Expand All @@ -16,7 +17,7 @@
//
// More documentation at https://nhooyr.io/websocket.
//
// Wasm
// # Wasm
//
// The client side supports compiling to Wasm.
// It wraps the WebSocket browser API.
Expand All @@ -25,8 +26,8 @@
//
// Some important caveats to be aware of:
//
// - Accept always errors out
// - Conn.Ping is no-op
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
// - Accept always errors out
// - Conn.Ping is no-op
// - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
// - *http.Response from Dial is &http.Response{} with a 101 status code on success
package websocket // import "nhooyr.io/websocket"
1 change: 1 addition & 0 deletions export_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions frame_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
2 changes: 1 addition & 1 deletion internal/test/wstest/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func EchoLoop(ctx context.Context, c *websocket.Conn) error {

c.SetReadLimit(1 << 30)

ctx, cancel := context.WithTimeout(ctx, time.Minute)
ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
defer cancel()

b := make([]byte, 32<<10)
Expand Down
1 change: 1 addition & 0 deletions internal/test/wstest/pipe.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package wstest
Expand Down
1 change: 1 addition & 0 deletions internal/wsjs/wsjs_js.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build js
// +build js

// Package wsjs implements typed access to the browser javascript WebSocket API.
Expand Down
17 changes: 17 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -eu

cd "$(dirname "$0")"

fmt() {
go mod tidy
gofmt -s -w .
goimports -w "-local=$(go list -m)" .
}

if ! command -v wasmbrowsertest >/dev/null; then
go install github.com/agnivade/wasmbrowsertest@latest
fi

fmt
go test -race --timeout=1h ./... "$@"
1 change: 1 addition & 0 deletions read.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down
1 change: 1 addition & 0 deletions write.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package websocket
Expand Down

0 comments on commit 6ead6aa

Please sign in to comment.