Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Sep 28, 2023
1 parent c5660ae commit 382864a
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 16 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
45 changes: 35 additions & 10 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,11 +50,11 @@ 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)
Expand Down Expand Up @@ -105,45 +112,63 @@ func wstestClientServer(ctx context.Context) (url string, closeFn func(), err er
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(context.Background(), time.Hour)
defer func() {
if err != nil {
cancel()
}
}()

wd, err := os.Getwd()
if err != nil {
return "", nil, err
}

var args []string
args = append(args, "run", "-it", "--rm",
-v "${PWD}/config:/specFile", \
-v "${PWD}/reports:/reports", \
"-p=9001:9001", \
"--name=fuzzingserver", \
"crossbario/autobahn-testsuite",
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),
"--name=fuzzingserver",
"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",
)
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)
}

// TODO: kill
return url, func() {
// TODO: super kill
wstest.Process.Kill()
}, 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
#AUTOBAHN=1 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 382864a

Please sign in to comment.